GNOME Bugzilla – Bug 519645
silently discarding tp_new leads to bugs in pickle/unpickle of at least enums
Last modified: 2008-03-02 00:06:15 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
Created attachment 106305 [details] [review] fix
Looks obviously correct. Test would be appreciated, but not really necessary.
Sending ChangeLog Sending gobject/gobjectmodule.c Transmitting file data .. Committed revision 747.