[Zodb-checkins] CVS: Zope/lib/python/ZODB - coptimizations.c:1.17.60.3

Jeremy Hylton jeremy@zope.com
Fri, 13 Dec 2002 16:27:39 -0500


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv11305

Modified Files:
      Tag: Zope-2_6-branch
	coptimizations.c 
Log Message:
Add some more comments and add XDECREFs to avoid leaks.
Remove redundant check of ExtensionClass in get_class().


=== Zope/lib/python/ZODB/coptimizations.c 1.17.60.2 => 1.17.60.3 ===
--- Zope/lib/python/ZODB/coptimizations.c:1.17.60.2	Thu Dec 12 14:04:13 2002
+++ Zope/lib/python/ZODB/coptimizations.c	Fri Dec 13 16:27:38 2002
@@ -81,14 +81,17 @@
 		PyErr_Clear();
 		return 0;
 	    }
-	    if (!PyExtensionClass_Check(class) ||
-		!(((PyExtensionClass*)class)->class_flags 
+	    /* The __class__ must be an extension class. */
+	    if (!(((PyExtensionClass*)class)->class_flags 
 		  & PERSISTENT_TYPE_FLAG)) {
 		Py_DECREF(class);
 		return 0;
 	    }
 	}
 	else
+	    /* Most objects will exit via this path.  They are neither
+	       extension classes nor instances of them.
+	    */
 	    return 0;
     }
     *out_class = class;
@@ -156,21 +159,20 @@
 static PyObject *
 persistent_id_call(persistent_id *self, PyObject *args, PyObject *kwargs)
 {
-    PyObject *object, *oid, *klass=NULL;
+    PyObject *object, *oid=NULL, *klass=NULL;
     PyObject *t1, *t2;
     int setjar = 0;
 
     if (!PyArg_ParseTuple(args, "O", &object))
 	return NULL;
 
-    /* If it is an extension class, get the class. */
+    /* If it is not an extension class, get the object's class. */
     if (!get_class(object, &klass))
 	goto return_none;
 
     oid = PyObject_GetAttr(object, py__p_oid);
     if (!oid) {
 	PyErr_Clear();
-	Py_XDECREF(klass);
 	goto return_none;
     }
 
@@ -203,7 +205,8 @@
 	|| PyObject_HasAttr(klass, py___getinitargs__))
 	goto return_oid;
 
-    if (!klass)  /* pass through ZClass special case */
+    /* If this is an extension class, just return _p_oid. */
+    if (!klass)
 	goto return_oid;
     t2 = get_class_tuple(klass, oid);
     if (!t2)
@@ -230,6 +233,8 @@
     return oid;
 
  return_none:
+    Py_XDECREF(oid);
+    Py_XDECREF(klass);
     Py_INCREF(Py_None);
     return Py_None;
 }