After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 640434 - Fix segfault when accessing __grefcount__ before creating the GObject
Fix segfault when accessing __grefcount__ before creating the GObject
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-24 16:03 UTC by Steve Frécinaux
Modified: 2012-04-04 13:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix segfault when accessing __grefcount__ before creating the GObject (1.12 KB, patch)
2011-01-24 16:03 UTC, Steve Frécinaux
none Details | Review
Fix segfault when accessing __grefcount__ before creating the GObject (1.19 KB, patch)
2011-02-09 00:28 UTC, Steve Frécinaux
none Details | Review
Fix segfault when accessing __grefcount__ before creating the GObject (2.22 KB, patch)
2011-02-09 17:35 UTC, Steve Frécinaux
needs-work Details | Review

Description Steve Frécinaux 2011-01-24 16:03:22 UTC
SSIA
Comment 1 Steve Frécinaux 2011-01-24 16:03:25 UTC
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 2 johnp 2011-01-26 20:44:21 UTC
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?
Comment 3 Steve Frécinaux 2011-01-26 22:35:57 UTC
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.
Comment 4 Steve Frécinaux 2011-02-09 00:28:16 UTC
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.
Comment 5 Steve Frécinaux 2011-02-09 17:35:04 UTC
Created attachment 180494 [details] [review]
Fix segfault when accessing __grefcount__ before creating the GObject

Now with a test case!
Comment 6 Martin Pitt 2012-02-10 08:39:12 UTC
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!
Comment 7 Martin Pitt 2012-04-04 13:33:11 UTC
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