[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeModuleTemplate.c:1.1.2.15 BTreeTemplate.c:1.1.2.21 BucketTemplate.c:1.1.2.20 SetTemplate.c:1.1.2.9

Jeremy Hylton jeremy@zope.com
Thu, 6 Jun 2002 19:16:13 -0400


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

Modified Files:
      Tag: Zope-3x-branch
	BTreeModuleTemplate.c BTreeTemplate.c BucketTemplate.c 
	SetTemplate.c 
Log Message:
Important fixes for weaklist and gc and persistence support.

The key issues is that when an object is being cleared or deallocated,
the persistence machinery needs to be cleared first.  If it isn't,
then the deallocation routines for the objects will mark the object as
changed and register it with the current transaction.  A dying object
should never be registered with a transaction; it leads to bizarre and
hard to debug errors.

BTreeModuleTemplate.c:
    Use PyPersist_HEAD instead of PyPersist_INSTANCE_HEAD,
    because we don't want BTrees to have an __dict__.

    po_weaklist is a PyObject *, not a PyObject **

BTreeTemplate.c:
    BTree_dealloc():
        Do the weakref support dance as documented in the library manual.
        Call base persistence dealloc next.
        Don't call _BTree_clear() if the object is already a ghost.

    BTree_traverse():
        Re-enable it.

    BTree_tp_clear():
        Call base persistence clear first.
        Don't call _BTree_clear() if the object is already a ghost.

	Presumably we don't do the weakref dance here, because it will
	be done in the constructor.

BucketTemplate.c:
    Exactly the same logic as for the corresponding functions in
    BTreeTemplate.c


SetTemplate.c:
    tp_clear slot should contain bucket_tp_clear not bucket_clear!




=== Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c 1.1.2.14 => 1.1.2.15 ===
 #ifdef PERSISTENT
 #define sizedcontainer_HEAD         \
-    PyPersist_INSTANCE_HEAD         \
-    PyObject **po_weaklist;         \
+    PyPersist_HEAD                  \
+    PyObject *po_weaklist;          \
     int size;                       \
     int len;
 #else


=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.1.2.20 => 1.1.2.21 ===
 BTree_dealloc(BTree *self)
 {
-    _BTree_clear(self);
+    if (self->po_weaklist != NULL)
+        PyObject_ClearWeakRefs((PyObject *)self);
     PyPersist_BASE_TYPE->tp_dealloc((PyObject *)self);
+    if (self->po_state != GHOST)
+	_BTree_clear(self);
 }
 
 static int
@@ -1271,11 +1274,6 @@
     int err = 0;
     int i, len;
     
-    /* XXX Unclear whether this routine causes a problem or merely reveals a
-     * XXX different problem.
-     */
-    return 0;
-
 #define VISIT(SLOT)                             \
     if (SLOT) {                                 \
         err = visit((PyObject *)(SLOT), arg);   \
@@ -1317,14 +1315,9 @@
 static int
 BTree_tp_clear(BTree *self)
 {
-    _BTree_clear(self);
-    /* XXX use base class tp_clear */
-    Py_XDECREF(self->po_dm);
-    Py_XDECREF(self->po_oid);
-    Py_XDECREF(self->po_serial);
-    self->po_dm = NULL;
-    self->po_oid = NULL;
-    self->po_serial = NULL;
+    PyPersist_BASE_TYPE->tp_clear((PyObject *)self);
+    if (self->po_state != GHOST)
+	_BTree_clear(self);
     return 0;
 }
 


=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.1.2.19 => 1.1.2.20 ===
 bucket_dealloc(Bucket *self)
 {
-    _bucket_clear(self);
+    if (self->po_weaklist != NULL)
+        PyObject_ClearWeakRefs((PyObject *)self);
     PyPersist_BASE_TYPE->tp_dealloc((PyObject *)self);
+    if (self->po_state != GHOST) 
+	_bucket_clear(self);
 }
 
 static int
@@ -1186,11 +1189,6 @@
     int err = 0;
     int i, len;
 
-    /* XXX Unclear whether this routine causes a problem or merely reveals a
-     * XXX different problem.
-     */
-    return 0;
-
 #define VISIT(SLOT)                             \
     if (SLOT) {                                 \
         err = visit((PyObject *)(SLOT), arg);   \
@@ -1237,13 +1235,9 @@
 int
 bucket_tp_clear(Bucket *self)
 {
-    _bucket_clear(self);
-    Py_XDECREF(self->po_dm);
-    Py_XDECREF(self->po_oid);
-    Py_XDECREF(self->po_serial);
-    self->po_dm = NULL;
-    self->po_oid = NULL;
-    self->po_serial = NULL;
+    PyPersist_BASE_TYPE->tp_clear((PyObject *)self);
+    if (self->po_state != GHOST)
+	_bucket_clear(self);
     return 0;
 }
 


=== Zope3/lib/python/Persistence/BTrees/SetTemplate.c 1.1.2.8 => 1.1.2.9 ===
     0,					/* tp_doc */
     (traverseproc)bucket_traverse,	/* tp_traverse */
-    (inquiry)bucket_clear,		/* tp_clear */
+    (inquiry)bucket_tp_clear,		/* tp_clear */
     0,					/* tp_richcompare */
     offsetof(Bucket, po_weaklist),	/* tp_weaklistoffset */
     0,					/* tp_iter */