[Zope3-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.13

Jeremy Hylton jeremy@zope.com
Thu, 18 Jul 2002 16:00:40 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv16186

Modified Files:
	cPersistence.c 
Log Message:
Fix abuse of tuples to avoid an INCREF.

The code was using a short-lived one-tuple.  It placed the element in
the tuple but did not INCREF it.  Just before deallocating the tuple,
it assigned the element to NULL.  This was dodgy at best, and plain
old fatal if the garbage collector runs while the tuple is alive.


=== Zope3/lib/python/Persistence/cPersistence.c 1.12 => 1.13 ===
 	Py_DECREF(meth);
 	return NULL;
     }
+    Py_INCREF(self);
     PyTuple_SET_ITEM(arg, 0, (PyObject *)self);
     result = PyObject_Call(meth, arg, NULL);
-    PyTuple_SET_ITEM(arg, 0, NULL);
     Py_DECREF(arg);
     Py_DECREF(meth);
     return result;
@@ -94,9 +94,9 @@
 	Py_DECREF(meth);
 	return NULL;
     }
+    Py_INCREF(self);
     PyTuple_SET_ITEM(arg, 0, (PyObject *)self);
     result = PyObject_Call(meth, arg, NULL);
-    PyTuple_SET_ITEM(arg, 0, NULL);
     Py_DECREF(arg);
     Py_DECREF(meth);
     return result;
@@ -151,9 +151,9 @@
     args = PyTuple_New(1);
     if (args == NULL)
 	goto register_error;
+    Py_INCREF(self);
     PyTuple_SET_ITEM(args, 0, (PyObject *)self);
     ret = PyObject_Call(reg, args, NULL);
-    PyTuple_SET_ITEM(args, 0, NULL);
     if (ret == NULL)
 	goto register_error;
     Py_DECREF(ret);