mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02: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:
@@ -45,6 +45,7 @@ struct _GSimpleAction
|
|||||||
GVariantType *parameter_type;
|
GVariantType *parameter_type;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
GVariant *state;
|
GVariant *state;
|
||||||
|
gboolean state_set_already;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef GObjectClass GSimpleActionClass;
|
typedef GObjectClass GSimpleActionClass;
|
||||||
@@ -232,7 +233,20 @@ g_simple_action_set_property (GObject *object,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_STATE:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -470,7 +484,7 @@ g_simple_action_class_init (GSimpleActionClass *class)
|
|||||||
P_("The state the action is in"),
|
P_("The state the action is in"),
|
||||||
G_VARIANT_TYPE_ANY,
|
G_VARIANT_TYPE_ANY,
|
||||||
NULL,
|
NULL,
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user