[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeTemplate.c:1.1.2.3
Jeremy Hylton
jeremy@zope.com
Wed, 27 Feb 2002 00:44:01 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv10734
Modified Files:
Tag: Zope-3x-branch
BTreeTemplate.c
Log Message:
Reformat BTree_split(), BTree_clone(), BTree_grow(),
BTree_lastBucket(), BTree_deleteNextBucket(), _BTree_set(),
BTree_setitem(), _BTree_clear(), BTree_getstate(),
_BTree_setstate(), BTree_setstate(), BTree_dealloc().
(In search of refcount bugs, none found yet.)
=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.1.2.2 => 1.1.2.3 === (896/996 lines abridged)
BTree_split(BTree *self, int index, BTree *next)
{
- int next_size;
- ASSERT(self->len > 1, "split of empty tree", -1);
+ int next_size;
+ ASSERT(self->len > 1, "split of empty tree", -1);
- if (index < 0 || index >= self->len) index=self->len/2;
+ if (index < 0 || index >= self->len)
+ index = self->len/2;
- next_size=self->len-index;
- ASSERT(next_size > 0, "split creates empty tree", -1);
+ next_size = self->len - index;
+ ASSERT(next_size > 0, "split creates empty tree", -1);
- UNLESS (next->data=PyMalloc(sizeof(BTreeItem)*next_size)) return -1;
- memcpy(next->data, self->data+index, sizeof(BTreeItem)*next_size);
- next->size=next->len=next_size;
+ next->data = PyMalloc(sizeof(BTreeItem) * next_size);
+ if (!next->data)
+ return -1;
+ memcpy(next->data, self->data+index, sizeof(BTreeItem) * next_size);
+ next->size = next->len = next_size;
- self->len = index;
+ self->len = index;
- if (SameType_Check(self, next->data->value))
- {
- PER_USE_OR_RETURN(BTREE(next->data->value), -1);
- next->firstbucket = BTREE(next->data->value)->firstbucket;
- Py_XINCREF(next->firstbucket);
- PER_ALLOW_DEACTIVATION(BTREE(next->data->value));
- PER_ACCESSED(BTREE(next->data->value));
- }
- else
- {
- next->firstbucket = BUCKET(next->data->value);
- Py_XINCREF(next->firstbucket);
+ if (SameType_Check(self, next->data->value)) {
+ PER_USE_OR_RETURN(BTREE(next->data->value), -1);
+ next->firstbucket = BTREE(next->data->value)->firstbucket;
+ Py_XINCREF(next->firstbucket);
+ PER_ALLOW_DEACTIVATION(BTREE(next->data->value));
+ PER_ACCESSED(BTREE(next->data->value));
+ } else {
+ next->firstbucket = BUCKET(next->data->value);
+ Py_XINCREF(next->firstbucket);
}
[-=- -=- -=- 896 lines omitted -=- -=- -=-]
+
+ self->len=len;
}
-
- return 0;
+
+ return 0;
}
static PyObject *
BTree_setstate(BTree *self, PyObject *args)
{
- int r;
+ int r;
- if (!PyArg_ParseTuple(args,"O",&args)) return NULL;
+ if (!PyArg_ParseTuple(args,"O",&args))
+ return NULL;
- PER_PREVENT_DEACTIVATION(self);
- r=_BTree_setstate(self, args, 0);
- PER_ALLOW_DEACTIVATION(self);
- PER_ACCESSED(self);
-
- if (r < 0) return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ PER_PREVENT_DEACTIVATION(self);
+ r=_BTree_setstate(self, args, 0);
+ PER_ALLOW_DEACTIVATION(self);
+ PER_ACCESSED(self);
+
+ if (r < 0)
+ return NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
}
#ifdef PERSISTENT
@@ -1251,8 +1222,8 @@
static void
BTree_dealloc(BTree *self)
{
- _BTree_clear(self);
- PyPersist_TYPE->tp_dealloc((PyObject *)self);
+ _BTree_clear(self);
+ PyPersist_TYPE->tp_dealloc((PyObject *)self);
}
static int