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

Jeremy Hylton jeremy@zope.com
Thu, 12 Dec 2002 14:04:13 -0500


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

Modified Files:
      Tag: Zope-2_6-branch
	coptimizations.c 
Log Message:
Apparent fix for ZClass persistent_id problem.

There are no tests for the problem, and I don't know how to right
one.  Checking this in because it seems like an obvious logic bug.



=== Zope/lib/python/ZODB/coptimizations.c 1.17.60.1 => 1.17.60.2 ===
--- Zope/lib/python/ZODB/coptimizations.c:1.17.60.1	Tue Nov 12 16:13:58 2002
+++ Zope/lib/python/ZODB/coptimizations.c	Thu Dec 12 14:04:13 2002
@@ -69,8 +69,8 @@
 /* Returns the klass of a persistent object.
    Returns NULL for other objects.
 */
-static PyObject *
-get_class(PyObject *object)
+int
+get_class(PyObject *object, PyObject **out_class)
 {
     PyObject *class = NULL;
 
@@ -79,19 +79,20 @@
 	    class = PyObject_GetAttr(object, py___class__);
 	    if (!class) {
 		PyErr_Clear();
-		return NULL;
+		return 0;
 	    }
 	    if (!PyExtensionClass_Check(class) ||
 		!(((PyExtensionClass*)class)->class_flags 
 		  & PERSISTENT_TYPE_FLAG)) {
 		Py_DECREF(class);
-		return NULL;
+		return 0;
 	    }
 	}
 	else
-	    return NULL;
+	    return 0;
     }
-    return class;
+    *out_class = class;
+    return 1;
 }
 
 /* Return a two-tuple of the class's module and name.
@@ -162,14 +163,14 @@
     if (!PyArg_ParseTuple(args, "O", &object))
 	return NULL;
 
-    klass = get_class(object);
-    if (!klass)
+    /* If it is an extension class, get the class. */
+    if (!get_class(object, &klass))
 	goto return_none;
 
     oid = PyObject_GetAttr(object, py__p_oid);
     if (!oid) {
 	PyErr_Clear();
-	Py_DECREF(klass);
+	Py_XDECREF(klass);
 	goto return_none;
     }
 
@@ -202,11 +203,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) /* pass through ZClass special case */
-	goto return_oid;
     t1 = PyTuple_New(2);
     if (!t1) {
 	Py_DECREF(t2);