[Zope3-checkins] CVS: Zope3/src/zope/app/container - _zope_app_container_contained.c:1.2.10.4

Jim Fulton jim at zope.com
Fri Jan 30 11:31:27 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv13143

Modified Files:
      Tag: zope3-zodb3-devel-branch
	_zope_app_container_contained.c 
Log Message:
Fixed a leak in the implementation of __setstate__.

Rewrote the CLEAR macro to hide the necessary temporary variable.


=== Zope3/src/zope/app/container/_zope_app_container_contained.c 1.2.10.3 => 1.2.10.4 ===
--- Zope3/src/zope/app/container/_zope_app_container_contained.c:1.2.10.3	Fri Jan 30 11:16:56 2004
+++ Zope3/src/zope/app/container/_zope_app_container_contained.c	Fri Jan 30 11:31:27 2004
@@ -53,6 +53,9 @@
 #define OBJECT(O) ((PyObject*)(O))
 #define Proxy_GET_OBJECT(ob)   (((ProxyObject *)(ob))->proxy_object)
 
+#define CLEAR(O) \
+  if (O) {PyObject *clr__tmp = O; O = NULL; Py_DECREF(clr__tmp); }
+
 /* Supress inclusion of the original proxy.h */
 #define _proxy_H_ 1
 
@@ -132,10 +135,20 @@
 static PyObject *
 CP_setstate(ProxyObject *self, PyObject *state)
 {
-  if(! PyArg_ParseTuple(state, "OO", &self->__parent__, &self->__name__))
+  PyObject *parent, *name;
+
+  if(! PyArg_ParseTuple(state, "OO", &parent, &name))
     return NULL;
-  Py_INCREF(self->__parent__);
-  Py_INCREF(self->__name__);
+
+  CLEAR(self->__parent__);
+  CLEAR(self->__name__);
+
+  Py_INCREF(parent);
+  Py_INCREF(name);
+
+  self->__parent__ = parent;
+  self->__name__ = name;
+
   Py_INCREF(Py_None);
   return Py_None;
 }
@@ -231,12 +244,9 @@
   return 0;
 }
 
-#define CLEAR(O) tmp = O; O = NULL; Py_XDECREF(tmp);
-
 static int
 CP_clear(ProxyObject *self)
 {
-  PyObject *tmp;
   /* XXXX Drop references that may have created reference
      cycles. Immutable objects do not have to define this method
      since they can never directly create reference cycles. Note
@@ -247,7 +257,6 @@
   */
   if (cPersistenceType->tp_clear != NULL)
     cPersistenceType->tp_clear((PyObject*)self);
-
   
   CLEAR(self->po_serial);
   CLEAR(self->proxy_object);
@@ -260,8 +269,6 @@
 static void
 CP_dealloc(ProxyObject *self)
 {
-  PyObject *tmp;
-
   if (self->po_weaklist != NULL)
     PyObject_ClearWeakRefs((PyObject *)self);
 




More information about the Zope3-Checkins mailing list