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

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


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

Modified Files:
	coptimizations.c 
Log Message:
Possible fix for ZClass problem with persistent_id().

The get_class() function will not find a class for a ZClass, but it
shouldn't fail.  Fix this by making the class an output paramter got
get_class() and returning 1/0 for success / failure.  A ZClass should
succeed trivially because it is not an extension class.


=== ZODB3/ZODB/coptimizations.c 1.20 => 1.21 ===
--- ZODB3/ZODB/coptimizations.c:1.20	Mon Sep 30 12:02:32 2002
+++ ZODB3/ZODB/coptimizations.c	Thu Dec 12 13:52:21 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);