Skip default-value for non-transformable properties

If we can't transform a property default value to string, we are not
going to add a default-value attribute to the GIR. This is necessary
because non-transformable values may not always be pointers, so we
cannot default to "NULL".
This commit is contained in:
Emmanuele Bassi 2023-01-08 14:20:06 +00:00
parent 3063615313
commit 967f993108

20
gdump.c
View File

@ -137,20 +137,22 @@ value_to_string (const GValue *value)
else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING)) else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
{ {
GValue tmp = G_VALUE_INIT; GValue tmp = G_VALUE_INIT;
char *s; char *s = NULL;
g_value_init (&tmp, G_TYPE_STRING); g_value_init (&tmp, G_TYPE_STRING);
g_value_transform (value, &tmp);
if (g_value_transform (value, &tmp))
s = g_strescape (g_value_get_string (&tmp), NULL); s = g_strescape (g_value_get_string (&tmp), NULL);
g_value_unset (&tmp); g_value_unset (&tmp);
if (s == NULL) if (s == NULL)
return g_strdup ("NULL"); return NULL;
return s; return s;
} }
else else
return g_strdup ("NULL"); return NULL;
} }
static void static void
@ -184,11 +186,21 @@ dump_properties (GType type, GOutputStream *out)
const GValue *v = g_param_spec_get_default_value (prop); const GValue *v = g_param_spec_get_default_value (prop);
char *default_value = value_to_string (v); char *default_value = value_to_string (v);
if (default_value != NULL)
{
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\" default-value=\"%s\"/>\n", escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\" default-value=\"%s\"/>\n",
prop->name, prop->name,
g_type_name (prop->value_type), g_type_name (prop->value_type),
prop->flags, prop->flags,
default_value); default_value);
}
else
{
escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\"/>\n",
prop->name,
g_type_name (prop->value_type),
prop->flags);
}
g_free (default_value); g_free (default_value);
} }