[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees - BucketTemplate.c:1.21 BTreeTemplate.c:1.46 BTreeModuleTemplate.c:1.14

Jeremy Hylton jeremy@zope.com
Thu, 10 Oct 2002 17:36:18 -0400


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

Modified Files:
	BucketTemplate.c BTreeTemplate.c BTreeModuleTemplate.c 
Log Message:
Eliminate BasePersistent! (Take two.)

All Zope3 tests pass with python CVS and python 2.2.2b1.

Python 2.2 has peculiar rules about whether a type's instances should
have an __dict__, which have been fixed in 2.3.  The new rules make
the BasePersistent unnecessary, because Persistent does not need to
explicitly create an __dict__.

There is a vast simplification to the code by eliminating
BasePersistent and the corresponding C type.  All C code uses a single
type (PyPersist_TYPE) and struct (PyPersistObject *).  Yay!

But we've still got to support Python 2.2 (bummer) and it's two big a
change to make some version of 2.2 behave like 2.3.  So we still need
some sort of hack to make this all work with 2.2.  The answer is a
persistent meta class that sets the dictoffset correctly and adds an
__dict__ descriptor.

The change has fairly broad changes to the Persistence package,
because the Python code already used PersistentMetaClass for
persistent clas support.  Rename that meta class to
PersistentClassMetaClass, which is descriptive but too verbose.  (Then
again all the names are too verbose.)


=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.20 => 1.21 ===
--- Zope3/lib/python/Persistence/BTrees/BucketTemplate.c:1.20	Thu Oct 10 04:20:07 2002
+++ Zope3/lib/python/Persistence/BTrees/BucketTemplate.c	Thu Oct 10 17:36:17 2002
@@ -1455,7 +1455,7 @@
     if (self->ob_type == &BucketType)
 	assert(self->ob_type->tp_dictoffset == 0);
 
-    err = PyPersist_BASE_TYPE->tp_traverse((PyObject *)self, visit, arg);
+    err = PyPersist_TYPE->tp_traverse((PyObject *)self, visit, arg);
     if (err)
 	goto Done;
 
@@ -1496,7 +1496,7 @@
 int
 bucket_tp_clear(Bucket *self)
 {
-    PyPersist_BASE_TYPE->tp_clear((PyObject *)self);
+    PyPersist_TYPE->tp_clear((PyObject *)self);
     if (self->po_state != GHOST)
 	_bucket_clear(self);
     return 0;


=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.45 => 1.46 ===
--- Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c:1.45	Thu Oct 10 04:20:07 2002
+++ Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c	Thu Oct 10 17:36:17 2002
@@ -1825,7 +1825,7 @@
     if (self->ob_type == &BTreeType)
 	assert(self->ob_type->tp_dictoffset == 0);
 
-    err = PyPersist_BASE_TYPE->tp_traverse((PyObject *)self, visit, arg);
+    err = PyPersist_TYPE->tp_traverse((PyObject *)self, visit, arg);
     if (err)
 	goto Done;
 
@@ -1861,7 +1861,7 @@
 static int
 BTree_tp_clear(BTree *self)
 {
-    PyPersist_BASE_TYPE->tp_clear((PyObject *)self);
+    PyPersist_TYPE->tp_clear((PyObject *)self);
     if (self->po_state != GHOST)
 	_BTree_clear(self);
     return 0;


=== Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c 1.13 => 1.14 ===
--- Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c:1.13	Thu Oct 10 04:20:07 2002
+++ Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c	Thu Oct 10 17:36:17 2002
@@ -394,7 +394,7 @@
 init_persist_type(PyTypeObject *type)
 {
     type->ob_type = &PyType_Type;
-    type->tp_base = PyPersist_BASE_TYPE;
+    type->tp_base = PyPersist_TYPE;
 
     if (PyType_Ready(type) < 0)
 	return 0;