GNOME Bugzilla – Bug 654627
GParamSpec: intern property names
Last modified: 2011-07-26 11:44:57 UTC
gparam.c currently contains some rather curious code for the case that we are installing a property without the G_PARAM_STATIC_NAME flag: pspec->name = g_strdup (name); canonicalize_key (pspec->name); g_intern_string (pspec->name); This seems quite useless. It interns the string, but doesn't use the interned string for the copy stored in the GParamSpec. We should just use it.
Created attachment 191983 [details] [review] GParamSpec: intern property names Make it so that the ->name property on all GParamSpec objects is an interned string.
We could also consider changing the 'gchar *name' in the GParamSpec struct. This is theoretically an API break but is only noticed if people are accessing it directly in unsafe ways (ie: via non-const pointer). Even then, it's just a warning.
Review of attachment 191983 [details] [review]: Looks fine to me; has the feel of a microoptimization, if anything. We should, however, document that pspec->name is an interned string, if we want to guarantee this.
Comment on attachment 191983 [details] [review] GParamSpec: intern property names The fact that the string is always interned is the main point of this patch, so addings docs for that is clearly a good idea. I did that and pushed the commit. The question remains about if we should change the "gchar *" to "const gchar *". It's certainly the "more correct" thing to do.
I think this change breaks gtk3.0.x with glib master: (gdb) bt
+ Trace 227814
<cosimoc> davidz, that's fixed already in gtk master <davidz> cosimoc: I shouldn't have to install gtk+ master just to use glib master... (and I never do since I don't really hack on gtk+ but I hack a lot on glib) cosimoc: but of course if it's a gtk+ bug trigger by a legitimate change then, meh <-- gogo13 has quit (gogo13) <cosimoc> davidz, GTK+ used an evil hack indeed <cosimoc> not that the current hack is much better <davidz> ok
"Officially" I consider that Gtk had a bug. The fact that the code in question contains /* FIXME: hack hack hack */ just before the problematic code should help convince you of the same. :)
Clearly, the gtk side is to blame here. I'll try to get a release out soon to have things work together again.