[Python-checkins] python/dist/src/Modules cPickle.c,2.73.2.1.2.2,2.73.2.1.2.3

mwh@users.sourceforge.net mwh@users.sourceforge.net
Tue, 24 Sep 2002 04:53:37 -0700


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

Modified Files:
      Tag: release22-maint
	cPickle.c 
Log Message:
backport jhylton's checkin of
    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.


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.73.2.1.2.2
retrieving revision 2.73.2.1.2.3
diff -C2 -d -r2.73.2.1.2.2 -r2.73.2.1.2.3
*** cPickle.c	22 Sep 2002 08:21:45 -0000	2.73.2.1.2.2
--- cPickle.c	24 Sep 2002 11:53:34 -0000	2.73.2.1.2.3
***************
*** 1675,1679 ****
  static int
  save_global(Picklerobject *self, PyObject *args, PyObject *name) {
!     PyObject *global_name = 0, *module = 0, *mod = 0, *moddict = 0, *klass = 0;
      char *name_str, *module_str;
      int module_size, name_size, res = -1;
--- 1675,1679 ----
  static int
  save_global(Picklerobject *self, PyObject *args, PyObject *name) {
!     PyObject *global_name = 0, *module = 0, *mod = 0, *klass = 0;
      char *name_str, *module_str;
      int module_size, name_size, res = -1;
***************
*** 1708,1713 ****
  	goto finally;
      }
!     moddict = PyModule_GetDict(mod);        /* borrowed ref */
!     klass = PyDict_GetItemString(moddict, name_str);        /* borrowed ref */
      if (klass == NULL) {
  	cPickle_ErrFormat(PicklingError,
--- 1708,1712 ----
  	goto finally;
      }
!     klass = PyObject_GetAttrString(mod, name_str);
      if (klass == NULL) {
  	cPickle_ErrFormat(PicklingError,
***************
*** 1717,1720 ****
--- 1716,1720 ----
      }
      if (klass != args) {
+ 	Py_DECREF(klass);
  	cPickle_ErrFormat(PicklingError,
  			  "Can't pickle %s: it's not the same object as %s.%s",
***************
*** 1722,1725 ****
--- 1722,1726 ----
  	goto finally;
      }
+     Py_DECREF(klass);
  
      if ((*self->write_func)(self, &global, 1) < 0)