GParam: try to avoid further invalid uses

In an attempt to avoid some potential future abuses of the GParamSpec
API, qualify the 'name' field of the structure as 'const' and add a
comment noting that it is an interned string.

This is a theoretical API break, but it will only ever result in
warnings -- and even then, only if you were already doing something
questionable.

Clean up some of the warnings that were caused internally in gparam.c
from these changes.
This commit is contained in:
Ryan Lortie 2011-07-21 08:33:50 +02:00
parent 9bcb3d7457
commit 706b275116
2 changed files with 23 additions and 18 deletions

View File

@ -917,7 +917,7 @@ g_param_spec_pool_insert (GParamSpecPool *pool,
GParamSpec *pspec,
GType owner_type)
{
gchar *p;
const gchar *p;
if (pool && pspec && owner_type > 0 && pspec->owner_type == 0)
{
@ -995,26 +995,31 @@ param_spec_ht_lookup (GHashTable *hash_table,
if (!pspec && !is_canonical (param_name))
{
gchar *canonical;
canonical = g_strdup (key.name);
canonicalize_key (canonical);
/* try canonicalized form */
key.name = g_strdup (param_name);
key.name = canonical;
key.owner_type = owner_type;
canonicalize_key (key.name);
if (walk_ancestors)
do
{
pspec = g_hash_table_lookup (hash_table, &key);
if (pspec)
{
g_free (key.name);
return pspec;
}
key.owner_type = g_type_parent (key.owner_type);
}
while (key.owner_type);
do
{
pspec = g_hash_table_lookup (hash_table, &key);
if (pspec)
{
g_free (canonical);
return pspec;
}
key.owner_type = g_type_parent (key.owner_type);
}
while (key.owner_type);
else
pspec = g_hash_table_lookup (hash_table, &key);
g_free (key.name);
pspec = g_hash_table_lookup (hash_table, &key);
g_free (canonical);
}
return pspec;

View File

@ -205,7 +205,7 @@ struct _GParamSpec
{
GTypeInstance g_type_instance;
gchar *name;
const gchar *name; /* interned string */
GParamFlags flags;
GType value_type;
GType owner_type; /* class or interface using this property */