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 519645 - silently discarding tp_new leads to bugs in pickle/unpickle of at least enums
silently discarding tp_new leads to bugs in pickle/unpickle of at least enums
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-29 22:44 UTC by Paul Pogonyshev
Modified: 2008-03-02 00:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix (599 bytes, patch)
2008-02-29 22:44 UTC, Paul Pogonyshev
committed Details | Review

Description Paul Pogonyshev 2008-02-29 22:44:21 UTC
gobjectmodule.c contains these lines:

#define REGISTER_TYPE(d, type, name) \
    type.ob_type = &PyType_Type; \
    type.tp_alloc = PyType_GenericAlloc; \
    type.tp_new = PyType_GenericNew; \
    ...

I'm not sure they are needed at all (except for 'ob_type' assignment), but some '.c' files actively set 'tp_new' to some custom function.  And fail because the custom function is not called when it should be.

The result is (at least) that pickling/unpickling enumeration values doesn't work:

>>> import pickle, gtk
>>> gtk.JUSTIFY_RIGHT == pickle.loads (pickle.dumps (gtk.JUSTIFY_RIGHT, -1))
__main__:1: Warning: comparing different enum types: GtkJustification and (null)
False

Attached patch fixes 'tp_new' and 'tp_alloc' overrides.  As a side-effect, pickling/unpickling is back to normal:

>>> import pickle, gtk
>>> gtk.JUSTIFY_RIGHT == pickle.loads (pickle.dumps (gtk.JUSTIFY_RIGHT, -1))
True
Comment 1 Paul Pogonyshev 2008-02-29 22:44:54 UTC
Created attachment 106305 [details] [review]
fix
Comment 2 Johan (not receiving bugmail) Dahlin 2008-02-29 23:03:05 UTC
Looks obviously correct. Test would be appreciated, but not really necessary.
Comment 3 Paul Pogonyshev 2008-03-02 00:06:15 UTC
Sending        ChangeLog
Sending        gobject/gobjectmodule.c
Transmitting file data ..
Committed revision 747.