GNOME Bugzilla – Bug 442747
crashers in python bindings
Last modified: 2007-06-14 19:06:56 UTC
Hi, attached patch should fix 3 potential crashers in the Python bindings. 1) If you pass a non-callable to add_monitor, it would happily invoke it. This is fixed by adding PyCallable_Check. 2) If you pass a lambda it would still segfault, because it was using PyObject_CallObject instead of the more general PyEval_CallObject. 3) If the user data was omitted, the python field would be junk. Fixed by setting it to null.
Created attachment 89142 [details] [review] fix 3 crashers
Thanks. Can you commit after changing the coding style to match what's used in gmenu.c? That is: + if (!PyCallable_Check (pycallback)) + { + PyErr_SetString (PyExc_TypeError, "parameter must be callable"); + return NULL; + }
Ok, turned out the real crasher was not what I thought - instead it was that gnome-menus needed to acquire the global Python lock when invoking callbacks. This new patch seems to be a reliable fix. I'll commit it later if no one objects.
Created attachment 89445 [details] [review] fixes for python binding crashers
It looks like most python bindings are using pyg_gil_state_ensure() and pyg_gil_state_release() from pygobject.
Right, those are the PyGTK wrappers around the core Python functions which they use for compatibility with older versions of Python (2.2 and below). But right now gnome-menus doesn't depend on pygobject. Python 2.3 was released just about 4 years ago now, it seems reasonable to me to depend on it. What do you think?
I know nothing about python bindings: I'm just looking at other bindings to see what they're doing :-) If you're confident about this, just go ahead. Or you can ask Mark.
Committed.