mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
GSimpleAction: don't allow changing state type
g_object_set() allowed us to bypass the usual checks that the state doesn't change type and also leaked. Fix that up by turning the state into a construct property (so that it always gets set once during construction, even if only to NULL) and then route the further sets through the C API so that they are subject to the same checks. https://bugzilla.gnome.org/show_bug.cgi?id=696424
This commit is contained in:
parent
908d7d6d6a
commit
83869120bb
@ -45,6 +45,7 @@ struct _GSimpleAction
|
||||
GVariantType *parameter_type;
|
||||
gboolean enabled;
|
||||
GVariant *state;
|
||||
gboolean state_set_already;
|
||||
};
|
||||
|
||||
typedef GObjectClass GSimpleActionClass;
|
||||
@ -232,7 +233,20 @@ g_simple_action_set_property (GObject *object,
|
||||
break;
|
||||
|
||||
case PROP_STATE:
|
||||
action->state = g_value_dup_variant (value);
|
||||
/* The first time we see this (during construct) we should just
|
||||
* take the state as it was handed to us.
|
||||
*
|
||||
* After that, we should make sure we go through the same checks
|
||||
* as the C API.
|
||||
*/
|
||||
if (!action->state_set_already)
|
||||
{
|
||||
action->state = g_value_dup_variant (value);
|
||||
action->state_set_already = TRUE;
|
||||
}
|
||||
else
|
||||
g_simple_action_set_state (action, g_value_get_variant (value));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -470,7 +484,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
||||
P_("The state the action is in"),
|
||||
G_VARIANT_TYPE_ANY,
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user