[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeModuleTemplate.c:1.1.2.5 BTreeTemplate.c:1.1.2.5 BucketTemplate.c:1.1.2.6 MergeTemplate.c:1.1.2.4 SetTemplate.c:1.1.2.6
Jeremy Hylton
jeremy@zope.com
Thu, 28 Feb 2002 17:40:49 -0500
Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv26295
Modified Files:
Tag: Zope-3x-branch
BTreeModuleTemplate.c BTreeTemplate.c BucketTemplate.c
MergeTemplate.c SetTemplate.c
Log Message:
Rename PyMalloc and PyRealloc to BTree_Malloc and BTree_Realloc.
Do not convert errors raised by _p_resolveConflict() to
ConflictError. If some other exception is raised, it is a bug in the
bucket code.
=== Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c 1.1.2.4 => 1.1.2.5 ===
static void *
-PyMalloc(size_t sz)
+BTree_Malloc(size_t sz)
{
- void *r;
+ void *r;
- ASSERT(sz > 0, "non-positive size malloc", NULL);
+ ASSERT(sz > 0, "non-positive size malloc", NULL);
- if ((r=malloc(sz))) return r;
+ r = malloc(sz);
+ if (r)
+ return r;
- PyErr_NoMemory();
- return NULL;
+ PyErr_NoMemory();
+ return NULL;
}
static void *
-PyRealloc(void *p, size_t sz)
+BTree_Realloc(void *p, size_t sz)
{
- void *r;
+ void *r;
- ASSERT(sz > 0, "non-positive size realloc", NULL);
+ ASSERT(sz > 0, "non-positive size realloc", NULL);
- if (p) r=realloc(p,sz);
- else r=malloc(sz);
-
- UNLESS (r) PyErr_NoMemory();
-
- return r;
+ if (p)
+ r = realloc(p, sz);
+ else
+ r = malloc(sz);
+
+ UNLESS (r)
+ PyErr_NoMemory();
+
+ return r;
}
#include "BTreeItemsTemplate.c"
=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.1.2.4 => 1.1.2.5 ===
ASSERT(next_size > 0, "split creates empty tree", -1);
- next->data = PyMalloc(sizeof(BTreeItem) * next_size);
+ next->data = BTree_Malloc(sizeof(BTreeItem) * next_size);
if (!next->data)
return -1;
memcpy(next->data, self->data+index, sizeof(BTreeItem) * next_size);
@@ -133,7 +133,7 @@
goto err;
/* Create a new data buffer to hold two BTrees */
- d = PyMalloc(sizeof(BTreeItem)*2);
+ d = BTree_Malloc(sizeof(BTreeItem)*2);
if (d == NULL)
goto err;
@@ -190,13 +190,13 @@
if (self->len == self->size) {
if (self->size) {
- d = PyRealloc(self->data, sizeof(BTreeItem)*self->size*2);
+ d = BTree_Realloc(self->data, sizeof(BTreeItem)*self->size*2);
if (d == NULL)
return -1;
self->data = d;
self->size *= 2;
} else {
- d = PyMalloc(sizeof(BTreeItem) * 2);
+ d = BTree_Malloc(sizeof(BTreeItem) * 2);
if (d == NULL)
return -1;
self->data = d;
@@ -580,40 +580,36 @@
static PyObject *
BTree_getstate(BTree *self, PyObject *args)
{
- PyObject *r=0, *o;
+ PyObject *r = NULL, *o;
int i, l;
PER_USE_OR_RETURN(self, NULL);
- if (self->len)
- {
- UNLESS (r=PyTuple_New(self->len*2-1)) goto err;
+ if (self->len) {
+ r = PyTuple_New(self->len * 2 - 1);
+ if (r == NULL)
+ goto err;
if (self->len == 1
&& self->data->value->ob_type != self->ob_type
#ifdef PERSISTENT
&& BUCKET(self->data->value)->po_oid == NULL
#endif
- )
- {
+ ) {
/* We have just one bucket. Save it's data directly. */
o = bucket_getstate((Bucket *)self->data->value);
if (o == NULL)
goto err;
PyTuple_SET_ITEM(r, 0, o);
ASSIGN(r, Py_BuildValue("(O)", r));
- }
- else
- {
- for (i=0, l=0; i < self->len; i++)
- {
- if (i)
- {
+ } else {
+ for (i=0, l=0; i < self->len; i++) {
+ if (i) {
COPY_KEY_TO_OBJECT(o, self->data[i].key);
- PyTuple_SET_ITEM(r,l,o);
+ PyTuple_SET_ITEM(r, l, o);
l++;
}
- o=self->data[i].value;
+ o = self->data[i].value;
Py_INCREF(o);
PyTuple_SET_ITEM(r,l,o);
l++;
@@ -621,9 +617,7 @@
ASSIGN(r, Py_BuildValue("OO", r, self->firstbucket));
}
- }
- else
- {
+ } else {
r = Py_None;
Py_INCREF(r);
}
@@ -636,6 +630,7 @@
err:
PER_ALLOW_DEACTIVATION(self);
PER_ACCESSED(self);
+ Py_XDECREF(r);
return NULL;
}
@@ -659,7 +654,7 @@
len = (len + 1) / 2;
if (len > self->size) {
- UNLESS (d = PyRealloc(self->data, sizeof(BTreeItem)*len))
+ UNLESS (d = BTree_Realloc(self->data, sizeof(BTreeItem)*len))
return -1;
self->data=d;
self->size=len;
@@ -669,7 +664,8 @@
if (i) {
COPY_KEY_FROM_ARG(d->key, PyTuple_GET_ITEM(items,l), copied);
l++;
- UNLESS (&copied) return -1;
+ if (!copied)
+ return -1;
INCREF_KEY(d->key);
}
d->value = PyTuple_GET_ITEM(items, l);
@@ -1028,7 +1024,7 @@
static PyObject *
BTree_keys(BTree *self, PyObject *args)
{
- return BTree_rangeSearch(self,args, 'k');
+ return BTree_rangeSearch(self, args, 'k');
}
/*
@@ -1037,7 +1033,7 @@
static PyObject *
BTree_values(BTree *self, PyObject *args)
{
- return BTree_rangeSearch(self,args,'v');
+ return BTree_rangeSearch(self, args, 'v');
}
/*
@@ -1046,7 +1042,7 @@
static PyObject *
BTree_items(BTree *self, PyObject *args)
{
- return BTree_rangeSearch(self,args,'i');
+ return BTree_rangeSearch(self, args, 'i');
}
static PyObject *
=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.1.2.5 => 1.1.2.6 ===
if (self->size) {
- keys = PyRealloc(self->keys, sizeof(KEY_TYPE)*self->size*2);
+ keys = BTree_Realloc(self->keys, sizeof(KEY_TYPE) * self->size * 2);
if (keys == NULL)
return -1;
if (!noval) {
- values = PyRealloc(self->values,
- sizeof(VALUE_TYPE) * self->size * 2);
+ values = BTree_Realloc(self->values,
+ sizeof(VALUE_TYPE) * self->size * 2);
if (values == NULL)
return -1;
- self->values=values;
+ self->values = values;
}
self->keys = keys;
self->size *= 2;
} else {
- self->keys = PyMalloc(sizeof(KEY_TYPE) * MIN_BUCKET_ALLOC);
+ self->keys = BTree_Malloc(sizeof(KEY_TYPE) * MIN_BUCKET_ALLOC);
if (self->keys == NULL)
return -1;
if (!noval) {
- self->values = PyMalloc(sizeof(VALUE_TYPE) * MIN_BUCKET_ALLOC);
+ self->values = BTree_Malloc(sizeof(VALUE_TYPE) * MIN_BUCKET_ALLOC);
if (self->values == NULL)
return -1;
}
@@ -297,7 +297,6 @@
} else
Py_INCREF(seq);
-
iter = PyObject_GetIter(seq);
if (iter == NULL)
goto err;
@@ -310,6 +309,7 @@
break;
}
if (!PyTuple_Check(o) || !PyTuple_GET_SIZE(o) == 2) {
+ Py_DECREF(o);
PyErr_SetString(PyExc_TypeError,
"Sequence must contain 2-item tuples");
goto err;
@@ -369,12 +369,12 @@
next_size = self->len-index;
- next->keys = PyMalloc(sizeof(KEY_TYPE) * next_size);
+ next->keys = BTree_Malloc(sizeof(KEY_TYPE) * next_size);
if (!next->keys)
return -1;
memcpy(next->keys, self->keys + index, sizeof(KEY_TYPE) * next_size);
if (self->values) {
- next->values = PyMalloc(sizeof(VALUE_TYPE) * next_size);
+ next->values = BTree_Malloc(sizeof(VALUE_TYPE) * next_size);
if (!next->values)
/* XXX does this leak the keys? */
return -1;
@@ -942,10 +942,10 @@
}
if (len > self->size) {
- keys = PyRealloc(self->keys, sizeof(KEY_TYPE)*len);
+ keys = BTree_Realloc(self->keys, sizeof(KEY_TYPE)*len);
if (keys == NULL)
return -1;
- values = PyRealloc(self->values, sizeof(VALUE_TYPE)*len);
+ values = BTree_Realloc(self->values, sizeof(VALUE_TYPE)*len);
if (values == NULL)
return -1;
self->keys = keys;
@@ -1078,17 +1078,6 @@
Py_DECREF(b[0]);
Py_DECREF(b[1]);
Py_DECREF(b[2]);
-
- if (r == NULL) {
- PyObject *error;
- PyObject *value;
- PyObject *traceback;
-
- PyErr_Fetch(&error, &value, &traceback);
- Py_INCREF(ConflictError);
- Py_XDECREF(error);
- PyErr_Restore(ConflictError, value, traceback);
- }
return r;
}
=== Zope3/lib/python/Persistence/BTrees/MergeTemplate.c 1.1.2.3 => 1.1.2.4 ===
merge_output(Bucket *r, SetIteration *i, int mapping)
{
- if(r->len >= r->size && Bucket_grow(r, ! mapping) < 0) return -1;
- COPY_KEY(r->keys[r->len], i->key);
- INCREF_KEY(r->keys[r->len]);
- if (mapping)
- {
- COPY_VALUE(r->values[r->len], i->value);
- INCREF_VALUE(r->values[r->len]);
+ if (r->len >= r->size && Bucket_grow(r, !mapping) < 0)
+ return -1;
+ COPY_KEY(r->keys[r->len], i->key);
+ INCREF_KEY(r->keys[r->len]);
+ if (mapping) {
+ COPY_VALUE(r->values[r->len], i->value);
+ INCREF_VALUE(r->values[r->len]);
}
- r->len++;
- return 0;
+ r->len++;
+ return 0;
}
static PyObject *
@@ -60,26 +60,28 @@
SetIteration i1 = {0,0,0}, i2 = {0,0,0}, i3 = {0,0,0};
int cmp12, cmp13, cmp23, mapping=0, set;
- if (initSetIteration(&i1, OBJECT(s1), 0, &mapping) < 0) return NULL;
- if (initSetIteration(&i2, OBJECT(s2), 0, &mapping) < 0) return NULL;
- if (initSetIteration(&i3, OBJECT(s3), 0, &mapping) < 0) return NULL;
+ if (initSetIteration(&i1, OBJECT(s1), 0, &mapping) < 0)
+ goto err;
+ if (initSetIteration(&i2, OBJECT(s2), 0, &mapping) < 0)
+ goto err;
+ if (initSetIteration(&i3, OBJECT(s3), 0, &mapping) < 0)
+ goto err;
- set = ! mapping;
+ set = !mapping;
if (mapping)
- {
- UNLESS(r=BUCKET(PyObject_CallObject(OBJECT(&BucketType), NULL)))
- goto err;
- }
+ r = (Bucket *)PyObject_CallObject((PyObject *)&BucketType, NULL);
else
- {
- UNLESS(r=BUCKET(PyObject_CallObject(OBJECT(&SetType), NULL)))
- goto err;
- }
-
- if (i1.next(&i1) < 0) return NULL;
- if (i2.next(&i2) < 0) return NULL;
- if (i3.next(&i3) < 0) return NULL;
+ r = (Bucket *)PyObject_CallObject((PyObject *)&SetType, NULL);
+ if (r == NULL)
+ goto err;
+
+ if (i1.next(&i1) < 0)
+ goto err;
+ if (i2.next(&i2) < 0)
+ goto err;
+ if (i3.next(&i3) < 0)
+ goto err;
while (i1.position >= 0 && i2.position >= 0 && i3.position >= 0)
{
=== Zope3/lib/python/Persistence/BTrees/SetTemplate.c 1.1.2.5 => 1.1.2.6 ===
if (l > self->size)
{
- UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*l)) return -1;
+ UNLESS (keys=BTree_Realloc(self->keys, sizeof(KEY_TYPE)*l)) return -1;
self->keys=keys;
self->size=l;
}