People apparently horribly misuse g_return_val_if_fail(). I gather, by the fact that it asserts (crashes) if glib is built with debug, that it’s intended to enforce contracts. And, mostly, that seems to be the way it’s used. However, some programs (*cough* gaim *cough*) seem to use it in place of “if (condition) return (failurecode)”, which means that building glib with debug causes constant cores in gaim. Here’s my most recent example:
if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") ||
(gaim_blist_node_get_string((GaimBlistNode*)chat,
"gtk-autojoin") != NULL))
serv_join_chat(gc, chat->components);
gaim_blist_node_get_<type> calls g_return_val_if_fail(result == <type>). Thus, the above snippet cannot fail to core if there is a gtk-autojoin option for this chat (which there will be), and glib is built with debug. I can only assume that a) Gaim developers don’t know about the assert case in glib; b) Gaim developers know, but don’t ever build glib with debug (and so don’t care); or c) Gaim developers don’t actually use the IRC client.
I’m only picking on gaim here because it’s the most recent example. Since rebuilding my glib with debug almost a month ago, tons of programs have become horribly unstable for the same reason. I’ve been hoping to fix these problems, and make things better for the Gentoo Gnome users, but there’s just too many, and I have to give up. Sorry, Gnome users, I need my desktop working again.
Note: the docs here for g_return_if_fail() don’t mention anything about asserts or contracts. “Critical message” doesn’t imply, to me at least, that it asserts. So, I guess the Gaim developers can’t really be blamed. I’m considering adding a big fat warning to the glib ebuild saying that you really don’t want to build with debug unless you know what you’re doing.
Update: I take it back. As far as I can tell, in glib 2.12, g_return_if_fail() always asserts, unless you actually give –disable-debug to glib (rather than not giving –enable-debug). This means that the above gaim code will always assert on Gentoo. I guess this means I’ll have to patch gaim.
Tags: Uncategorized by Daniel
3 Comments »