GNOME Bugzilla – Bug 619245
GType used by hook_up_vfunc_impl is not the right one when __gtype_name__ is not set.
Last modified: 2011-02-09 17:46:08 UTC
Created attachment 161597 [details] Short test case. When trying to implement a GInterface, there is a crash in pygi. Attached is a very simple test case. Here is a bit of stacktrace: Program received signal SIGSEGV, Segmentation fault. 0xb7aaee25 in _wrap_pyg_hook_up_vfunc_implementation (self=0x0, args=0x825c554) at gimodule.c:208 208 *method_ptr = closure->closure; (gdb) bt
+ Trace 222026
Versions involved: pygobject 2.21.1 pygi master (21/5/2010) python 2.5.5
In gimodule.c, in _wrap_pyg_hook_up_vfunc_implementation: The following lines are only triggered in the GInterface case: implementor_iface_class = g_type_interface_peek(implementor_class, ancestor_g_type); implementor_class = implementor_iface_class; implementor_iface_class is null, hence method_ptr = G_STRUCT_MEMBER_P(implementor_class, offset) is null too. The values for the variables listed here are: DEBUG: implementor_class = 0x9bc1ce0 DEBUG: implementor_iface_class = (nil) DEBUG: ancestor_g_type = GtkEditable (163453552) So basically it looks like implementor_gtype doesn't actually implement the GInterface...
Created attachment 161619 [details] [review] Fix crash in hook_up_vfunc_implementation when implementing GInterface If you don't set a __gtype_name__ attribute in your new GType when implementing a GInterface, then for some reason g_type_interface_peek() returns NULL and this causes hook_up_vfunc_implementation to crash. This patch doesn't fix the g_type_interface_peek() issue, but it at least avoids the crash by raising an exception instead.
Finally, it looks like the type passed to hook_up_vfunc_implementation is actually GtkWidget, not the type inheriting from both GtkWidget and GtkEditable. Also, it works when setting __g_type_name__ in the new class, because it triggers the gtype registration. As tomeu noticed, this means that the issue is actually triggered by the fact that the type hierarchies are not in sync between python and gtype: the type is already registered in python, but not yet in gtype, so we get the wrong class, and that class has no ginterface yet...
bug 616849 patch looks similar to the patch above, but it still wouldn't fix the fact that we can't implement a GInterface when we don't use __gtype_name__.
Review of attachment 161619 [details] [review]: Using patch from bug 616849, the crash is totally fixed and warns about how one has forgotten to use __gtype_name__. I'm rejecting this patch and changing the subject of the bug.
This has been resolved by systematically registering a new gtype at the Prage Python Hackfest 2011.