Commit 8cd1aea1 authored by Tim Peters's avatar Tim Peters

_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.
parent 6b975ad4
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.61 2002/06/17 23:55:48 tim_one Exp $\n" #define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.62 2002/06/18 22:56:01 tim_one Exp $\n"
/* /*
** _BTree_get ** _BTree_get
...@@ -777,15 +777,18 @@ _BTree_setstate(BTree *self, PyObject *state, int noval) ...@@ -777,15 +777,18 @@ _BTree_setstate(BTree *self, PyObject *state, int noval)
if ((len=PyTuple_Size(items)) < 0) return -1; if ((len=PyTuple_Size(items)) < 0) return -1;
len=(len+1)/2; 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) if (len > self->size)
{ {
UNLESS (d=PyRealloc(self->data, sizeof(BTreeItem)*len)) return -1; UNLESS (d = PyRealloc(self->data, sizeof(BTreeItem)*len)) return -1;
self->data=d; self->data = d;
self->size=len; 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) if (i)
{ {
...@@ -823,6 +826,7 @@ _BTree_setstate(BTree *self, PyObject *state, int noval) ...@@ -823,6 +826,7 @@ _BTree_setstate(BTree *self, PyObject *state, int noval)
l++; l++;
} }
assert(len > 0);
if (len) if (len)
{ {
if (! firstbucket) if (! firstbucket)
...@@ -839,9 +843,10 @@ _BTree_setstate(BTree *self, PyObject *state, int noval) ...@@ -839,9 +843,10 @@ _BTree_setstate(BTree *self, PyObject *state, int noval)
self->firstbucket = BUCKET(firstbucket); self->firstbucket = BUCKET(firstbucket);
Py_INCREF(firstbucket); Py_INCREF(firstbucket);
assert(firstbucket->ob_refcnt > 1);
} }
self->len=len; self->len = len;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment