[Python-checkins] CVS: python/dist/src/Modules cPickle.c,2.72,2.73

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 19 Dec 2001 08:57:02 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv12245

Modified Files:
	cPickle.c 
Log Message:
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().


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.72
retrieving revision 2.73
diff -C2 -d -r2.72 -r2.73
*** cPickle.c	2001/12/08 18:02:55	2.72
--- cPickle.c	2001/12/19 16:56:54	2.73
***************
*** 1991,1994 ****
--- 1991,1999 ----
      }
  
+     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) {