[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeTemplate.c:1.62

Tim Peters tim.one@comcast.net
Tue, 18 Jun 2002 18:56:01 -0400


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv13791

Modified Files:
	BTreeTemplate.c 
Log Message:
_BTree_setstate():  Added some C-level assert()s, trying to guess whether
some of this code is needed, and to help track down an odd bug Guido is
seeing.  assert()s won't trigger except in a debug build.


=== Zope/lib/python/BTrees/BTreeTemplate.c 1.61 => 1.62 ===
       if ((len=PyTuple_Size(items)) < 0) return -1;
       len=(len+1)/2;
+      assert(len > 0);
 
+      assert(self->size == 0); /* XXX we called _BTree_clear() above! */
+      assert(self->data == NULL); /* ditto */
       if (len > self->size)
         {
-          UNLESS (d=PyRealloc(self->data, sizeof(BTreeItem)*len)) return -1;
-          self->data=d;
-          self->size=len;
+          UNLESS (d = PyRealloc(self->data, sizeof(BTreeItem)*len)) return -1;
+          self->data = d;
+          self->size = len;
         }
 
-      for (i=0, d=self->data, l=0; i < len; i++, d++)
+      for (i = 0, d = self->data, l = 0; i < len; i++, d++)
         {
           if (i)
             {
@@ -823,6 +826,7 @@
           l++;
         }
 
+      assert(len > 0);
       if (len)
         {
           if (! firstbucket)
@@ -839,9 +843,10 @@
 
           self->firstbucket = BUCKET(firstbucket);
           Py_INCREF(firstbucket);
+          assert(firstbucket->ob_refcnt > 1);
         }
 
-      self->len=len;
+      self->len = len;
     }
 
   return 0;