[Zodb-checkins] CVS: ZODB3/ZODB - coptimizations.c:1.25

Jeremy Hylton jeremy at zope.com
Thu Dec 11 00:17:21 EST 2003


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

Modified Files:
	coptimizations.c 
Log Message:
Ignore descriptors in persistent_id() calls.

Apparent fix for the bug Sidnei reported today.  He didn't have a
simple test case, rather reported that starting Zope with Formulator
caused a crash.  I think this will fix the problem.

We had to do the same thing in Python code in ZODB4, but weren't
worrying about performance there.


=== ZODB3/ZODB/coptimizations.c 1.24 => 1.25 ===
--- ZODB3/ZODB/coptimizations.c:1.24	Fri Nov 28 11:44:49 2003
+++ ZODB3/ZODB/coptimizations.c	Thu Dec 11 00:16:50 2003
@@ -173,9 +173,39 @@
 	PyErr_Clear();
 	goto return_none;
     }
-
     if (oid != Py_None) {
-	PyObject *jar = PyObject_GetAttr(object, py__p_jar);
+	PyObject *jar;
+
+	if (!PyString_Check(oid)) {
+	    /* If the object is a class, then asking for _p_oid or
+	       _p_jar will return a descriptor.  There is no API to
+	       ask whether something is a descriptor; the best you
+	       can do is call anything with an __get__ a descriptor.
+
+	       The getattr check is potentially expensive so do the
+	       cheap PyString_Check() first, assuming that most oids
+	       that aren't None are real oids.  ZODB always uses
+	       strings, although some other user of Persistent could
+	       use something else.
+	    */
+	    static PyObject *__get__;
+	    PyObject *descr;
+	    if (!__get__) {
+		__get__ = PyString_InternFromString("__get__");
+		if (!__get__)
+		    goto err;
+	    }
+	    descr = PyObject_GetAttr(oid, __get__);
+	    if (descr)
+		goto return_none;
+	    /* Otherwise it's not a descriptor and it's just some
+	       weird value.  Maybe we'll get an error later.
+	    */
+
+	    /* XXX should check that this was an AttributeError */
+	    PyErr_Clear();
+	}
+	jar = PyObject_GetAttr(object, py__p_jar);
 	if (!jar)
 	    PyErr_Clear();
 	else {




More information about the Zodb-checkins mailing list