From: Jeremy Hylton Date: Tue, 16 Jul 2002 20:02:15 +0000 (+0000) Subject: Given the persistent id code a shot at a class before calling save_global(). X-Git-Tag: v2.2.2b1~264 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=634abb860729c6925fed275b149d8a570cc06c59;p=thirdparty%2FPython%2Fcpython.git Given the persistent id code a shot at a class before calling save_global(). Backported from the trunk. --- diff --git a/Lib/pickle.py b/Lib/pickle.py index eb360dd8f4c6..38bda79fc566 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -163,6 +163,11 @@ class Pickler: try: f = self.dispatch[t] except KeyError: + pid = self.inst_persistent_id(object) + if pid is not None: + self.save_pers(pid) + return + try: issc = issubclass(t, TypeType) except TypeError: # t is not a class @@ -171,11 +176,6 @@ class Pickler: self.save_global(object) return - pid = self.inst_persistent_id(object) - if pid is not None: - self.save_pers(pid) - return - try: reduce = dispatch_table[t] except KeyError: diff --git a/Modules/cPickle.c b/Modules/cPickle.c index adf7e4449f02..1f8b210ede4f 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1992,11 +1992,6 @@ 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; @@ -2004,6 +1999,11 @@ save(Picklerobject *self, PyObject *args, int pers_save) { } } + if (PyType_IsSubtype(type, &PyType_Type)) { + res = save_global(self, args, NULL); + goto finally; + } + if ((__reduce__ = PyDict_GetItem(dispatch_table, (PyObject *)type))) { Py_INCREF(__reduce__);