]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport jhylton's checkin of
authorMichael W. Hudson <mwh@python.net>
Tue, 24 Sep 2002 11:53:34 +0000 (11:53 +0000)
committerMichael W. Hudson <mwh@python.net>
Tue, 24 Sep 2002 11:53:34 +0000 (11:53 +0000)
    revision 2.87 of cPickle.c

Do more robust test of whether global objects are accessible.

PyImport_ImportModule() is not guaranteed to return a module object.
When another type of object was returned, the PyModule_GetDict() call
return NULL and the subsequent GetItem() seg faulted.

Bug fix candidate.

----------

Once again, whitespace chances scuppered automatic backporting, so
I did this by hand.  Review probably wise -- but I have run make test!

Also incorporates revision 2.88 which was just removing a now unused
declaration.

Modules/cPickle.c

index a400ddefdeac0d711b13d1f871fc743555f64ec5..ae2df8c21af10d3333cdd63b89efbf823fcc116f 100644 (file)
@@ -1674,7 +1674,7 @@ finally:
 
 static int
 save_global(Picklerobject *self, PyObject *args, PyObject *name) {
-    PyObject *global_name = 0, *module = 0, *mod = 0, *moddict = 0, *klass = 0;
+    PyObject *global_name = 0, *module = 0, *mod = 0, *klass = 0;
     char *name_str, *module_str;
     int module_size, name_size, res = -1;
 
@@ -1707,8 +1707,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
                          "OSS", args, module, global_name);
        goto finally;
     }
-    moddict = PyModule_GetDict(mod);        /* borrowed ref */
-    klass = PyDict_GetItemString(moddict, name_str);        /* borrowed ref */
+    klass = PyObject_GetAttrString(mod, name_str);
     if (klass == NULL) {
        cPickle_ErrFormat(PicklingError,
                          "Can't pickle %s: it's not found as %s.%s",
@@ -1716,11 +1715,13 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
        goto finally;
     }
     if (klass != args) {
+       Py_DECREF(klass);
        cPickle_ErrFormat(PicklingError,
                          "Can't pickle %s: it's not the same object as %s.%s",
                          "OSS", args, module, global_name);
        goto finally;
     }
+    Py_DECREF(klass);
 
     if ((*self->write_func)(self, &global, 1) < 0)
         goto finally;