]> granicus.if.org Git - python/commitdiff
Do more robust test of whether global objects are accessible.
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 11 Jul 2002 22:01:40 +0000 (22:01 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 11 Jul 2002 22:01:40 +0000 (22:01 +0000)
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.

Modules/cPickle.c

index 248436532bc88a8ef9f0ac1d39a1e791639b206b..84c1d4f18e0f8ed4ced27c08dccd4a3a919cc39d 100644 (file)
@@ -1719,10 +1719,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
                                  "OSS", args, module, global_name);
                goto finally;
        }
-       /* borrowed ref */
-       moddict = PyModule_GetDict(mod);        
-       /* borrowed ref */
-       klass = PyDict_GetItemString(moddict, name_str);        
+       klass = PyObject_GetAttrString(mod, name_str);
        if (klass == NULL) {
                cPickle_ErrFormat(PicklingError,
                                  "Can't pickle %s: it's not found as %s.%s",
@@ -1730,11 +1727,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;