[Zope-Checkins] CVS: ZODB3/ZODB - coptimizations.c:1.23

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


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv24902/ZODB

Modified Files:
	coptimizations.c 
Log Message:
Frontport changes from Zope 2.6 branch.

Get ZClasses working.  (Tested this time.)
Add some more comments and add XDECREFs to avoid leaks.
Remove redundant check of ExtensionClass in get_class().
Apparent fix for ZClass persistent_id problem.


=== ZODB3/ZODB/coptimizations.c 1.22 => 1.23 ===
--- ZODB3/ZODB/coptimizations.c:1.22	Thu Dec 12 14:02:07 2002
+++ ZODB3/ZODB/coptimizations.c	Fri Dec 13 16:56:05 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;
@@ -107,7 +110,7 @@
 	goto err;
     if (!PyObject_IsTrue(module)) {
 	Py_DECREF(module);
-	/* XXX Handle degenerate 1.x ZClass case. */
+	/* If the class has no __module__, it must be a degnerate ZClass. */
 	return oid;
     }
 
@@ -172,21 +175,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;
     }
 
@@ -219,11 +221,11 @@
 	|| PyObject_HasAttr(klass, py___getinitargs__))
 	goto return_oid;
 
-    if (!klass)  /* pass through ZClass special case */
-	goto return_oid;
     t2 = get_class_tuple(klass, oid);
     if (!t2)
 	goto err;
+    if (t2 == oid) /* Couldn't find class info, just used oid. */
+	goto return_oid;
     t1 = PyTuple_New(2);
     if (!t1) {
 	Py_DECREF(t2);
@@ -246,6 +248,8 @@
     return oid;
 
  return_none:
+    Py_XDECREF(oid);
+    Py_XDECREF(klass);
     Py_INCREF(Py_None);
     return Py_None;
 }