clutter: Stop using GParameter

The type has been deprecated, so stop using it. The easiest replacement
would be to add our own struct, but considering that separate name/value
arrays are easier to free (g_auto!) and we already do the split in one
place, go that route.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/689
This commit is contained in:
Florian Müllner 2019-07-18 00:03:23 +02:00
parent 4259cfd4c6
commit 9189b7b512

View File

@ -1636,14 +1636,17 @@ clutter_script_translate_parameters (ClutterScript *script,
GObject *object, GObject *object,
const gchar *name, const gchar *name,
GList *properties, GList *properties,
GArray **params) GPtrArray **param_names,
GArray **param_values)
{ {
ClutterScriptable *scriptable = NULL; ClutterScriptable *scriptable = NULL;
ClutterScriptableIface *iface = NULL; ClutterScriptableIface *iface = NULL;
GList *l, *unparsed; GList *l, *unparsed;
gboolean parse_custom = FALSE; gboolean parse_custom = FALSE;
*params = g_array_new (FALSE, FALSE, sizeof (GParameter)); *param_names = g_ptr_array_new_with_free_func (g_free);
*param_values = g_array_new (FALSE, FALSE, sizeof (GValue));
g_array_set_clear_func (*param_values, (GDestroyNotify) g_value_unset);
if (CLUTTER_IS_SCRIPTABLE (object)) if (CLUTTER_IS_SCRIPTABLE (object))
{ {
@ -1659,7 +1662,7 @@ clutter_script_translate_parameters (ClutterScript *script,
for (l = properties; l != NULL; l = l->next) for (l = properties; l != NULL; l = l->next)
{ {
PropertyInfo *pinfo = l->data; PropertyInfo *pinfo = l->data;
GParameter param = { NULL }; GValue value = G_VALUE_INIT;
gboolean res = FALSE; gboolean res = FALSE;
if (pinfo->is_child || pinfo->is_layout) if (pinfo->is_child || pinfo->is_layout)
@ -1676,12 +1679,12 @@ clutter_script_translate_parameters (ClutterScript *script,
pinfo->name); pinfo->name);
if (parse_custom) if (parse_custom)
res = iface->parse_custom_node (scriptable, script, &param.value, res = iface->parse_custom_node (scriptable, script, &value,
pinfo->name, pinfo->name,
pinfo->node); pinfo->node);
if (!res) if (!res)
res = _clutter_script_parse_node (script, &param.value, res = _clutter_script_parse_node (script, &value,
pinfo->name, pinfo->name,
pinfo->node, pinfo->node,
pinfo->pspec); pinfo->pspec);
@ -1693,9 +1696,8 @@ clutter_script_translate_parameters (ClutterScript *script,
continue; continue;
} }
param.name = g_strdup (pinfo->name); g_ptr_array_add (*param_names, g_strdup (pinfo->name));
g_array_append_val (*param_values, value);
g_array_append_val (*params, param);
property_info_free (pinfo); property_info_free (pinfo);
} }
@ -1710,7 +1712,8 @@ clutter_script_construct_parameters (ClutterScript *script,
GType gtype, GType gtype,
const gchar *name, const gchar *name,
GList *properties, GList *properties,
GArray **construct_params) GPtrArray **construct_param_names,
GArray **construct_param_values)
{ {
GObjectClass *klass; GObjectClass *klass;
GList *l, *unparsed; GList *l, *unparsed;
@ -1718,14 +1721,17 @@ clutter_script_construct_parameters (ClutterScript *script,
klass = g_type_class_ref (gtype); klass = g_type_class_ref (gtype);
g_assert (klass != NULL); g_assert (klass != NULL);
*construct_params = g_array_new (FALSE, FALSE, sizeof (GParameter)); *construct_param_names = g_ptr_array_new_with_free_func (g_free);
*construct_param_values = g_array_new (FALSE, FALSE, sizeof (GValue));
g_array_set_clear_func (*construct_param_values,
(GDestroyNotify) g_value_unset);
unparsed = NULL; unparsed = NULL;
for (l = properties; l != NULL; l = l->next) for (l = properties; l != NULL; l = l->next)
{ {
PropertyInfo *pinfo = l->data; PropertyInfo *pinfo = l->data;
GParameter param = { NULL }; GValue value = G_VALUE_INIT;
GParamSpec *pspec = NULL; GParamSpec *pspec = NULL;
/* we allow custom property names for classes, so if we /* we allow custom property names for classes, so if we
@ -1749,9 +1755,7 @@ clutter_script_construct_parameters (ClutterScript *script,
continue; continue;
} }
param.name = g_strdup (pinfo->name); if (!_clutter_script_parse_node (script, &value,
if (!_clutter_script_parse_node (script, &param.value,
pinfo->name, pinfo->name,
pinfo->node, pinfo->node,
pinfo->pspec)) pinfo->pspec))
@ -1760,7 +1764,8 @@ clutter_script_construct_parameters (ClutterScript *script,
continue; continue;
} }
g_array_append_val (*construct_params, param); g_ptr_array_add (*construct_param_names, g_strdup (pinfo->name));
g_array_append_val (*construct_param_values, value);
property_info_free (pinfo); property_info_free (pinfo);
} }
@ -2087,7 +2092,8 @@ _clutter_script_apply_properties (ClutterScript *script,
gboolean set_custom_property = FALSE; gboolean set_custom_property = FALSE;
GObject *object = oinfo->object; GObject *object = oinfo->object;
GList *properties; GList *properties;
GArray *params; g_autoptr (GPtrArray) param_names = NULL;
g_autoptr (GArray) param_values = NULL;
guint i; guint i;
if (!oinfo->has_unresolved) if (!oinfo->has_unresolved)
@ -2111,34 +2117,31 @@ _clutter_script_apply_properties (ClutterScript *script,
object, object,
oinfo->id, oinfo->id,
properties, properties,
&params); &param_names,
&param_values);
/* consume all the properties we could translate in this pass */ /* consume all the properties we could translate in this pass */
for (i = 0; i < params->len; i++) for (i = 0; i < param_names->len; i++)
{ {
GParameter *param = &g_array_index (params, GParameter, i); char *name = g_ptr_array_index (param_names, i);
GValue *value = &g_array_index (param_values, GValue, i);
CLUTTER_NOTE (SCRIPT, CLUTTER_NOTE (SCRIPT,
"Setting %s property '%s' (type:%s) to object '%s' (id:%s)", "Setting %s property '%s' (type:%s) to object '%s' (id:%s)",
set_custom_property ? "custom" : "regular", set_custom_property ? "custom" : "regular",
param->name, name,
g_type_name (G_VALUE_TYPE (&param->value)), g_type_name (G_VALUE_TYPE (value)),
g_type_name (oinfo->gtype), g_type_name (oinfo->gtype),
oinfo->id); oinfo->id);
if (set_custom_property) if (set_custom_property)
iface->set_custom_property (scriptable, script, iface->set_custom_property (scriptable, script,
param->name, name,
&param->value); value);
else else
g_object_set_property (object, param->name, &param->value); g_object_set_property (object, name, value);
g_free ((gchar *) param->name);
g_value_unset (&param->value);
} }
g_array_free (params, TRUE);
_clutter_script_check_unresolved (script, oinfo); _clutter_script_check_unresolved (script, oinfo);
} }
@ -2146,8 +2149,8 @@ void
_clutter_script_construct_object (ClutterScript *script, _clutter_script_construct_object (ClutterScript *script,
ObjectInfo *oinfo) ObjectInfo *oinfo)
{ {
GArray *params = NULL; g_autoptr (GPtrArray) param_names = NULL;
guint i; g_autoptr (GArray) param_values = NULL;
/* we have completely updated the object */ /* we have completely updated the object */
if (oinfo->object != NULL) if (oinfo->object != NULL)
@ -2190,25 +2193,14 @@ _clutter_script_construct_object (ClutterScript *script,
oinfo->gtype, oinfo->gtype,
oinfo->id, oinfo->id,
properties, properties,
&params); &param_names,
&param_values);
default_stage = clutter_stage_manager_get_default_stage (manager); default_stage = clutter_stage_manager_get_default_stage (manager);
oinfo->object = G_OBJECT (default_stage); oinfo->object = G_OBJECT (default_stage);
for (i = 0; i < params->len; i++)
{
GParameter *param = &g_array_index (params, GParameter, i);
g_free ((gchar *) param->name);
g_value_unset (&param->value);
}
g_array_free (params, TRUE);
} }
else else
{ {
g_autoptr (GPtrArray) param_names = NULL;
GArray *param_values;
GList *properties = oinfo->properties; GList *properties = oinfo->properties;
/* every other object: first, we get the construction parameters */ /* every other object: first, we get the construction parameters */
@ -2217,22 +2209,11 @@ _clutter_script_construct_object (ClutterScript *script,
oinfo->gtype, oinfo->gtype,
oinfo->id, oinfo->id,
properties, properties,
&params); &param_names,
&param_values);
/* Convert GParameter → (GStrv, GValue[]) */
param_names = g_ptr_array_sized_new (params->len);
param_values = g_array_sized_new (TRUE, FALSE, sizeof (GValue), params->len);
for (i = 0; i < params->len; i++)
{
GParameter *param = &g_array_index (params, GParameter, i);
g_ptr_array_add (param_names, (gchar *) param->name);
g_array_append_val (param_values, param->value);
}
g_ptr_array_add (param_names, NULL);
oinfo->object = g_object_new_with_properties (oinfo->gtype, oinfo->object = g_object_new_with_properties (oinfo->gtype,
params->len, param_names->len,
(const gchar **) param_names->pdata, (const gchar **) param_names->pdata,
(const GValue *) param_values->data); (const GValue *) param_values->data);
@ -2241,17 +2222,6 @@ _clutter_script_construct_object (ClutterScript *script,
* else too or only by this ClutterScript object. * else too or only by this ClutterScript object.
*/ */
g_object_ref_sink (oinfo->object); g_object_ref_sink (oinfo->object);
for (i = 0; i < params->len; i++)
{
GParameter *param = &g_array_index (params, GParameter, i);
g_free ((gchar *) param->name);
g_value_unset (&param->value);
}
g_array_free (param_values, FALSE);
g_array_free (params, TRUE);
} }
g_assert (oinfo->object != NULL); g_assert (oinfo->object != NULL);