From 706b2751166bb8590e41800d0b3c3056ba529daa Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Thu, 21 Jul 2011 08:33:50 +0200 Subject: [PATCH] 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. --- gobject/gparam.c | 39 ++++++++++++++++++++++----------------- gobject/gparam.h | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/gobject/gparam.c b/gobject/gparam.c index 5e9ffe0..656614e 100644 --- a/gobject/gparam.c +++ b/gobject/gparam.c @@ -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; diff --git a/gobject/gparam.h b/gobject/gparam.h index 8f5c04f..0a5240a 100644 --- a/gobject/gparam.h +++ b/gobject/gparam.h @@ -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 */ -- 2.7.4