Commit f7700783 authored by Tim Peters's avatar Tim Peters

_BTree_set(): Still on the trail of a bug here. Simplified some of the

code and slashed nesting depth, but no semantic changes yet.
parent 8fd36a69
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.39 2002/06/10 20:38:06 tim_one Exp $\n" #define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.40 2002/06/11 00:19:19 tim_one Exp $\n"
/* /*
** _BTree_get ** _BTree_get
...@@ -367,41 +367,45 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -367,41 +367,45 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
&bchanged); &bchanged);
if (grew < 0) if (grew < 0)
goto err; goto err;
if (grew == 0)
goto Done;
if (grew) { /* A bucket changed size. */
bchanged = 1; /* A bucket changed size */ bchanged = 1;
if (value) { /* got bigger */ if (value) {
if (SameType_Check(self, d->child)) { /* A bucket got bigger. */
if (BTREE(d->child)->len > MAX_BTREE_SIZE(d->child)) { int toobig;
if (BTree_grow(self, min, noval) < 0)
goto err; if (SameType_Check(self, d->child))
changed = 1; toobig = BTREE(d->child)->len > MAX_BTREE_SIZE(d->child);
} else
} toobig = BUCKET(d->child)->len > MAX_BUCKET_SIZE(d->child);
else {
if (BUCKET(d->child)->len > MAX_BUCKET_SIZE(d->child)) { if (toobig) {
if (BTree_grow(self, min, noval) < 0) if (BTree_grow(self, min, noval) < 0)
goto err; goto err;
changed = 1; changed = 1;
} }
goto Done;
} }
}
else { /* got smaller */ /* A bucket got smaller. */
if (min && grew > 1) { if (min && grew > 1) {
/* Somebody below us deleted their first bucket and */ /* Somebody below us deleted their first bucket and */
/* and an intermediate tree couldn't handle it. */ /* an intermediate tree couldn't handle it. */
if (BTree_deleteNextBucket(BTREE(d[-1].child)) < 0) if (BTree_deleteNextBucket(BTREE(d[-1].child)) < 0)
goto err; goto err;
grew = 1; /* Reset flag, since we handled it */ grew = 1; /* Reset flag, since we handled it */
} }
if (d->child->len > 0)
goto Done;
if (BUCKET(d->child)->len == 0) { /* Got empty */ /* The child became empty. */
if (!SameType_Check(self, d->child)) { if (!SameType_Check(self, d->child)) {
/* We are about to delete a bucket. */ /* We are about to delete a bucket. */
if (min) { if (min) {
/* If it's not our first bucket, we can tell the /* If it's not our first bucket, we can tell the
previous bucket to adjust it's reference to previous bucket to adjust it's reference to it. */
it. */
if (Bucket_deleteNextBucket(BUCKET(d[-1].child)) < 0) if (Bucket_deleteNextBucket(BUCKET(d[-1].child)) < 0)
goto err; goto err;
} }
...@@ -422,7 +426,6 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -422,7 +426,6 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
} }
if (min < self->len) if (min < self->len)
memmove(d, d+1, (self->len-min)*sizeof(BTreeItem)); memmove(d, d+1, (self->len-min)*sizeof(BTreeItem));
if (!min) { if (!min) {
if (self->len) { if (self->len) {
/* We just deleted our first child, so we need to /* We just deleted our first child, so we need to
...@@ -437,8 +440,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -437,8 +440,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
PER_ACCESSED(BTREE(self->data->child)); PER_ACCESSED(BTREE(self->data->child));
} }
else { else {
ASSIGNB(self->firstbucket, ASSIGNB(self->firstbucket, BUCKET(self->data->child));
BUCKET(self->data->child));
Py_INCREF(self->firstbucket); Py_INCREF(self->firstbucket);
} }
/* We can toss our first key now */ /* We can toss our first key now */
...@@ -449,11 +451,9 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -449,11 +451,9 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
self->firstbucket = 0; self->firstbucket = 0;
} }
} }
changed=1; changed = 1;
}
}
}
Done:
#ifdef PERSISTENT #ifdef PERSISTENT
if (changed if (changed
|| (bchanged /* The bucket changed */ || (bchanged /* The bucket changed */
...@@ -470,7 +470,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value, ...@@ -470,7 +470,7 @@ _BTree_set(BTree *self, PyObject *keyarg, PyObject *value,
PER_ACCESSED(self); PER_ACCESSED(self);
return grew; return grew;
err: err:
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
PER_ACCESSED(self); PER_ACCESSED(self);
return -1; return -1;
......
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