From: Guido van Rossum Date: Wed, 19 Dec 2001 16:56:54 +0000 (+0000) Subject: save(): Fix for SF bug #494904: Cannot pickle a class with a X-Git-Tag: v2.2.1c1~296 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=950dce6f01039bae5efdb8eedbe9ad48d81d0488;p=thirdparty%2FPython%2Fcpython.git save(): Fix for SF bug #494904: Cannot pickle a class with a metaclass, reported by Dan Parisien. Objects that are instances of custom metaclasses, i.e. whose ob_type is a subclass of PyType_Type, should be pickled the same as new-style classes (objects whose ob_type is PyType_Type). This can't be done through the existing dispatch switches, and the __reduce__ trick doesn't work for these, since it finds the unbound __reduce__ for instances of the class (inherited from PyBaseObject_Type). So check explicitly using PyType_IsSubtype(). --- diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 425ff10bb0ea..a4943ce8211e 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1990,6 +1990,11 @@ save(Picklerobject *self, PyObject *args, int pers_save) { } } + if (PyType_IsSubtype(type, &PyType_Type)) { + res = save_global(self, args, NULL); + goto finally; + } + if (!pers_save && self->inst_pers_func) { if ((tmp = save_pers(self, args, self->inst_pers_func)) != 0) { res = tmp;