[Zope3-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.26

Jeremy Hylton jeremy@zope.com
Thu, 7 Nov 2002 13:48:30 -0500


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv31456

Modified Files:
	cPersistence.c 
Log Message:
Fix for multiple inheritance with Python 2.2.

Based on patch from Phillip J. Eby.

The part of type that determines the best base class expects that the
dictoffset will always come before the weaklistoffset.  Make sure this
invariant is maintained by the PersistentMetaClass, so that it is
possible to inherit from multiple class that inherit from persistent.


=== Zope3/lib/python/Persistence/cPersistence.c 1.25 => 1.26 ===
--- Zope3/lib/python/Persistence/cPersistence.c:1.25	Thu Oct 31 10:51:32 2002
+++ Zope3/lib/python/Persistence/cPersistence.c	Thu Nov  7 13:48:30 2002
@@ -776,10 +776,12 @@
     if (!new)
 	return NULL;
 
-    new->tp_dictoffset = 0;
+    /* If a base class already defined a dictoffset, use that. */
+    new->tp_dictoffset = new->tp_base->tp_dictoffset;
 
     /* It is possible for a class that inherits from Persistent to
        define __slots__, in which case it shouldn't have a dict.
+       XXX This isn't ready yet.
     */
     if (PyObject_HasAttrString((PyObject *)new, "__slots__")) {
 	return (PyObject *)new;
@@ -787,8 +789,16 @@
 
     if (!new->tp_dictoffset) {
 	/* Update the type to know about __dict__. */
-	if (type->tp_itemsize)
+	if (new->tp_itemsize)
 	    new->tp_dictoffset = -(long)sizeof(PyObject *);
+	else if (new->tp_weaklistoffset && !new->tp_base->tp_weaklistoffset) {
+	    /* Python expects the weaklistoffset to come before the
+	       dictoffset.  The order matters to extra_ivars(), which
+	       is involved in determining the best base class.
+	    */
+	    new->tp_dictoffset = new->tp_weaklistoffset;
+	    new->tp_weaklistoffset = new->tp_basicsize;
+	}
 	else
 	    /* XXX Should be aligned properly */
 	    new->tp_dictoffset = type->tp_basicsize;