GNOME Bugzilla – Bug 419379
Modernize init_pygobject: use static inline functions instead of macros
Last modified: 2007-04-14 16:25:33 UTC
init_pygobject is the perfect example of a place where a static inline function is preferable to a macro. Macros make it more difficult to track down problems (see for instance bug 417004). And macros that contain 'return' statements are downright evil, with few exceptions.
Created attachment 84771 [details] [review] init_pygobject macro -> static inline pygobject_init Add a pygobject_init static inline function; make the old macros call this function. I've been using a similar solution in gnome-python/gnomevfs, for some time now, and no one has complained yet of any compilation problems. See http://svn.gnome.org/viewcvs/gnome-python/trunk/gnomevfs/pygnomevfs.h?view=markup
Created attachment 84773 [details] [review] patch v2 New version of patch that: 1. returns the module object or NULL instead of 0/-1, 2. Doesn't try to fetch the module dictionary, instead uses PyObject_GetAttrString.
Created attachment 84821 [details] [review] patch v3: more useful error reporting
+1 Note that it doesn't even need to be inline as this is not performance critical. Also, not using the module dictionary is a good thing because it could allow for lazy loading in environments without backward compatibility constraints.
An important side benefit of inline is that it also (I think) makes a function not compile in for object files that don't use it, thus avoiding duplicated code. So it's not just a performance issue, also a code size issue.
Committed revision 643.