GNOME Bugzilla – Bug 640434
Fix segfault when accessing __grefcount__ before creating the GObject
Last modified: 2012-04-04 13:33:11 UTC
SSIA
Created attachment 179181 [details] [review] Fix segfault when accessing __grefcount__ before creating the GObject When you create a new instance using Type() and you try to access __grefcount__ before calling the subclass's __init__ function, there used to be a segmentation fault because we were trying to access the not yet created object. With this patch applied, we will return 0 when there is no GObject instance available.
Comment on attachment 179181 [details] [review] Fix segfault when accessing __grefcount__ before creating the GObject Shouldn't we set an error and return NULL instead?
It seemed sensible to me to return '0' as it is a normal case, and __grefcount__ is only used for debug anyway. When you do PythonType(), the wrapper is created before the actual gobject (which is created in gobject.GObject.__init__()), so if you access __grefcount__ before calling that function, returning 0 seems the right thing to do.
Created attachment 180431 [details] [review] Fix segfault when accessing __grefcount__ before creating the GObject When you create a new instance using Type() and you try to access __grefcount__ before calling the subclass's __init__ function, there used to be a segmentation fault because we were trying to access the not yet created object. With this patch applied, we will return 0 when there is no GObject instance available.
Created attachment 180494 [details] [review] Fix segfault when accessing __grefcount__ before creating the GObject Now with a test case!
Comment on attachment 180494 [details] [review] Fix segfault when accessing __grefcount__ before creating the GObject If this is still relevant, can you please update the patch to apply to current master? I'm happy to review it quickly then. Thanks!
I updated the patch to current master, simplified the test case, and moved it to the other grefcount tests. Thanks! http://git.gnome.org/browse/pygobject/commit/?id=96f14989baea76fe8692f10c1a37e2dfc45fecbf