Commit bea890b8 authored by Tim Peters's avatar Tim Peters

Trimmed trailing whitespace.

parent 6b6b6622
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
Copyright (c) 2001, 2002 Zope Corporation and Contributors. Copyright (c) 2001, 2002 Zope Corporation and Contributors.
All Rights Reserved. All Rights Reserved.
This software is subject to the provisions of the Zope Public License, This software is subject to the provisions of the Zope Public License,
Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE FOR A PARTICULAR PURPOSE
****************************************************************************/ ****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.33 2002/06/06 19:30:21 jeremy Exp $\n" #define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.34 2002/06/08 15:57:48 tim_one Exp $\n"
/* /*
** _bucket_get ** _bucket_get
...@@ -33,7 +33,7 @@ _bucket_get(Bucket *self, PyObject *keyarg, int has_key) ...@@ -33,7 +33,7 @@ _bucket_get(Bucket *self, PyObject *keyarg, int has_key)
int min, max, i, l, cmp, copied=1; int min, max, i, l, cmp, copied=1;
PyObject *r; PyObject *r;
KEY_TYPE key; KEY_TYPE key;
COPY_KEY_FROM_ARG(key, keyarg, copied); COPY_KEY_FROM_ARG(key, keyarg, copied);
UNLESS (copied) return NULL; UNLESS (copied) return NULL;
...@@ -92,7 +92,7 @@ bucket_getitem(Bucket *self, PyObject *key) ...@@ -92,7 +92,7 @@ bucket_getitem(Bucket *self, PyObject *key)
** Returns: -1 on error, and MemoryError exception is set ** Returns: -1 on error, and MemoryError exception is set
** 0 on success ** 0 on success
*/ */
static int static int
Bucket_grow(Bucket *self, int newsize, int noval) Bucket_grow(Bucket *self, int newsize, int noval)
{ {
KEY_TYPE *keys; KEY_TYPE *keys;
...@@ -133,7 +133,7 @@ Bucket_grow(Bucket *self, int newsize, int noval) ...@@ -133,7 +133,7 @@ Bucket_grow(Bucket *self, int newsize, int noval)
Overflow: Overflow:
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
/* /*
...@@ -151,12 +151,12 @@ Overflow: ...@@ -151,12 +151,12 @@ Overflow:
** 1 on success with a new value (growth) ** 1 on success with a new value (growth)
*/ */
static int static int
_bucket_set(Bucket *self, PyObject *keyarg, PyObject *v, _bucket_set(Bucket *self, PyObject *keyarg, PyObject *v,
int unique, int noval, int *changed) int unique, int noval, int *changed)
{ {
int min, max, i, l, cmp, copied=1; int min, max, i, l, cmp, copied=1;
KEY_TYPE key; KEY_TYPE key;
COPY_KEY_FROM_ARG(key, keyarg, copied); COPY_KEY_FROM_ARG(key, keyarg, copied);
UNLESS(copied) return -1; UNLESS(copied) return -1;
...@@ -200,19 +200,19 @@ _bucket_set(Bucket *self, PyObject *keyarg, PyObject *v, ...@@ -200,19 +200,19 @@ _bucket_set(Bucket *self, PyObject *keyarg, PyObject *v,
self->len--; self->len--;
DECREF_KEY(self->keys[i]); DECREF_KEY(self->keys[i]);
if (i < self->len) if (i < self->len)
memmove(self->keys+i, self->keys+i+1, memmove(self->keys+i, self->keys+i+1,
sizeof(KEY_TYPE)*(self->len-i)); sizeof(KEY_TYPE)*(self->len-i));
if (self->values && ! noval) if (self->values && ! noval)
{ {
DECREF_VALUE(self->values[i]); DECREF_VALUE(self->values[i]);
if (i < self->len) if (i < self->len)
memmove(self->values+i, self->values+i+1, memmove(self->values+i, self->values+i+1,
sizeof(VALUE_TYPE)*(self->len-i)); sizeof(VALUE_TYPE)*(self->len-i));
} }
if (! self->len) if (! self->len)
{ {
self->size=0; self->size=0;
...@@ -317,7 +317,7 @@ Mapping_update(PyObject *self, PyObject *args) ...@@ -317,7 +317,7 @@ Mapping_update(PyObject *self, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
if (!PySequence_Check(seq)) if (!PySequence_Check(seq))
{ {
items = PyObject_GetAttr(seq, items_str); items = PyObject_GetAttr(seq, items_str);
...@@ -422,7 +422,7 @@ Bucket_nextBucket(Bucket *self, Bucket **r) ...@@ -422,7 +422,7 @@ Bucket_nextBucket(Bucket *self, Bucket **r)
return 0; return 0;
} }
static int static int
Bucket_deleteNextBucket(Bucket *self) Bucket_deleteNextBucket(Bucket *self)
{ {
PER_USE_OR_RETURN(self, -1); PER_USE_OR_RETURN(self, -1);
...@@ -442,14 +442,14 @@ Bucket_deleteNextBucket(Bucket *self) ...@@ -442,14 +442,14 @@ Bucket_deleteNextBucket(Bucket *self)
return -1; return -1;
} }
/* /*
Bucket_findRangeEnd -- Find the index of a range endpoint Bucket_findRangeEnd -- Find the index of a range endpoint
(possibly) contained in a bucket. (possibly) contained in a bucket.
Arguments: self The bucket Arguments: self The bucket
key the key to match against key the key to match against
low end flag low end flag
offset The output offset offset The output offset
If low, return bucket and index of the smallest item >= key, If low, return bucket and index of the smallest item >= key,
otherwise return bucket and index of the largest item <= key. otherwise return bucket and index of the largest item <= key.
...@@ -467,7 +467,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset) ...@@ -467,7 +467,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset)
PER_USE_OR_RETURN(self, -1); PER_USE_OR_RETURN(self, -1);
for (min=0, max=self->len, i=max/2, l=max; i != l; l=i, i=(min+max)/2) for (min=0, max=self->len, i=max/2, l=max; i != l; l=i, i=(min+max)/2)
{ {
TEST_KEY_SET_OR(cmp, self->keys[i], key) goto err; TEST_KEY_SET_OR(cmp, self->keys[i], key) goto err;
if (cmp < 0) if (cmp < 0)
...@@ -478,7 +478,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset) ...@@ -478,7 +478,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset)
PER_ACCESSED(self); PER_ACCESSED(self);
*offset=i; *offset=i;
return 1; return 1;
} }
else else
max=i; max=i;
} }
...@@ -486,10 +486,10 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset) ...@@ -486,10 +486,10 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset)
/* OK, no matches, pick max or min, depending on whether /* OK, no matches, pick max or min, depending on whether
we want an upper or low end. we want an upper or low end.
*/ */
if (low) if (low)
{ {
if (max == self->len) i=0; if (max == self->len) i=0;
else else
{ {
i=1; i=1;
*offset=max; *offset=max;
...@@ -498,7 +498,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset) ...@@ -498,7 +498,7 @@ Bucket_findRangeEnd(Bucket *self, PyObject *keyarg, int low, int *offset)
else else
{ {
if (max == 0) i=0; if (max == 0) i=0;
else else
{ {
i=1; i=1;
*offset=min; *offset=min;
...@@ -520,15 +520,15 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min) ...@@ -520,15 +520,15 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min)
{ {
PyObject *key=0; PyObject *key=0;
int rc, offset; int rc, offset;
if (args && ! PyArg_ParseTuple(args, "|O", &key)) return NULL; if (args && ! PyArg_ParseTuple(args, "|O", &key)) return NULL;
PER_USE_OR_RETURN(self, NULL); PER_USE_OR_RETURN(self, NULL);
UNLESS (self->len) goto empty; UNLESS (self->len) goto empty;
/* Find the low range */ /* Find the low range */
if (key) if (key)
{ {
if ((rc = Bucket_findRangeEnd(self, key, min, &offset)) <= 0) if ((rc = Bucket_findRangeEnd(self, key, min, &offset)) <= 0)
{ {
...@@ -544,7 +544,7 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min) ...@@ -544,7 +544,7 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min)
PER_ACCESSED(self); PER_ACCESSED(self);
return key; return key;
empty: empty:
PyErr_SetString(PyExc_ValueError, "empty bucket"); PyErr_SetString(PyExc_ValueError, "empty bucket");
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
...@@ -564,35 +564,35 @@ Bucket_maxKey(Bucket *self, PyObject *args) ...@@ -564,35 +564,35 @@ Bucket_maxKey(Bucket *self, PyObject *args)
return Bucket_maxminKey(self, args, 0); return Bucket_maxminKey(self, args, 0);
} }
static int static int
Bucket_rangeSearch(Bucket *self, PyObject *args, int *low, int *high) Bucket_rangeSearch(Bucket *self, PyObject *args, int *low, int *high)
{ {
PyObject *f=0, *l=0; PyObject *f=0, *l=0;
int rc; int rc;
if (args && ! PyArg_ParseTuple(args,"|OO",&f, &l)) return -1; if (args && ! PyArg_ParseTuple(args,"|OO",&f, &l)) return -1;
UNLESS (self->len) goto empty; UNLESS (self->len) goto empty;
/* Find the low range */ /* Find the low range */
if (f && f != Py_None) if (f && f != Py_None)
{ {
UNLESS (rc = Bucket_findRangeEnd(self, f, 1, low)) UNLESS (rc = Bucket_findRangeEnd(self, f, 1, low))
{ {
if (rc < 0) return -1; if (rc < 0) return -1;
goto empty; goto empty;
} }
} }
else *low = 0; else *low = 0;
/* Find the high range */ /* Find the high range */
if (l && l != Py_None) if (l && l != Py_None)
{ {
UNLESS (rc = Bucket_findRangeEnd(self, l, 0, high)) UNLESS (rc = Bucket_findRangeEnd(self, l, 0, high))
{ {
if (rc < 0) return -1; if (rc < 0) return -1;
goto empty; goto empty;
} }
} }
else *high=self->len - 1; else *high=self->len - 1;
...@@ -613,13 +613,13 @@ Bucket_rangeSearch(Bucket *self, PyObject *args, int *low, int *high) ...@@ -613,13 +613,13 @@ Bucket_rangeSearch(Bucket *self, PyObject *args, int *low, int *high)
** args (unused) ** args (unused)
** **
** Returns: list of bucket keys ** Returns: list of bucket keys
*/ */
static PyObject * static PyObject *
bucket_keys(Bucket *self, PyObject *args) bucket_keys(Bucket *self, PyObject *args)
{ {
PyObject *r=0, *key; PyObject *r=0, *key;
int i, low, high; int i, low, high;
PER_USE_OR_RETURN(self, NULL); PER_USE_OR_RETURN(self, NULL);
if (Bucket_rangeSearch(self, args, &low, &high) < 0) goto err; if (Bucket_rangeSearch(self, args, &low, &high) < 0) goto err;
...@@ -690,7 +690,7 @@ bucket_values(Bucket *self, PyObject *args) ...@@ -690,7 +690,7 @@ bucket_values(Bucket *self, PyObject *args)
** **
** Arguments: self The Bucket ** Arguments: self The Bucket
** args (unused) ** args (unused)
** **
** Returns: list of all items in the bucket ** Returns: list of all items in the bucket
*/ */
static PyObject * static PyObject *
...@@ -716,7 +716,7 @@ bucket_items(Bucket *self, PyObject *args) ...@@ -716,7 +716,7 @@ bucket_items(Bucket *self, PyObject *args)
COPY_VALUE_TO_OBJECT(o, self->values[i]); COPY_VALUE_TO_OBJECT(o, self->values[i]);
UNLESS (o) goto err; UNLESS (o) goto err;
PyTuple_SET_ITEM(item, 1, o); PyTuple_SET_ITEM(item, 1, o);
if (PyList_SetItem(r, i-low, item) < 0) goto err; if (PyList_SetItem(r, i-low, item) < 0) goto err;
item = 0; item = 0;
...@@ -748,16 +748,16 @@ bucket_byValue(Bucket *self, PyObject *args) ...@@ -748,16 +748,16 @@ bucket_byValue(Bucket *self, PyObject *args)
COPY_VALUE_FROM_ARG(min, omin, copied); COPY_VALUE_FROM_ARG(min, omin, copied);
UNLESS(copied) return NULL; UNLESS(copied) return NULL;
for (i=0, l=0; i < self->len; i++) for (i=0, l=0; i < self->len; i++)
if (TEST_VALUE(self->values[i], min) >= 0) if (TEST_VALUE(self->values[i], min) >= 0)
l++; l++;
UNLESS (r=PyList_New(l)) goto err; UNLESS (r=PyList_New(l)) goto err;
for (i=0, l=0; i < self->len; i++) for (i=0, l=0; i < self->len; i++)
{ {
if (TEST_VALUE(self->values[i], min) < 0) continue; if (TEST_VALUE(self->values[i], min) < 0) continue;
UNLESS (item = PyTuple_New(2)) goto err; UNLESS (item = PyTuple_New(2)) goto err;
COPY_KEY_TO_OBJECT(o, self->keys[i]); COPY_KEY_TO_OBJECT(o, self->keys[i]);
...@@ -770,7 +770,7 @@ bucket_byValue(Bucket *self, PyObject *args) ...@@ -770,7 +770,7 @@ bucket_byValue(Bucket *self, PyObject *args)
DECREF_VALUE(v); DECREF_VALUE(v);
UNLESS (o) goto err; UNLESS (o) goto err;
PyTuple_SET_ITEM(item, 0, o); PyTuple_SET_ITEM(item, 0, o);
if (PyList_SetItem(r, l, item) < 0) goto err; if (PyList_SetItem(r, l, item) < 0) goto err;
l++; l++;
...@@ -804,7 +804,7 @@ _bucket_clear(Bucket *self) ...@@ -804,7 +804,7 @@ _bucket_clear(Bucket *self)
{ {
int i; int i;
if (self->next) if (self->next)
{ {
Py_DECREF(self->next); Py_DECREF(self->next);
self->next=0; self->next=0;
...@@ -813,13 +813,13 @@ _bucket_clear(Bucket *self) ...@@ -813,13 +813,13 @@ _bucket_clear(Bucket *self)
for (i=self->len; --i >= 0; ) for (i=self->len; --i >= 0; )
{ {
DECREF_KEY(self->keys[i]); DECREF_KEY(self->keys[i]);
if (self->values) if (self->values)
{ {
DECREF_VALUE(self->values[i]); DECREF_VALUE(self->values[i]);
} }
} }
self->len=0; self->len=0;
if (self->values) if (self->values)
{ {
free(self->values); free(self->values);
self->values=0; self->values=0;
...@@ -861,7 +861,7 @@ bucket_clear(Bucket *self, PyObject *args) ...@@ -861,7 +861,7 @@ bucket_clear(Bucket *self, PyObject *args)
} }
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
PER_ACCESSED(self); PER_ACCESSED(self);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
err: err:
...@@ -891,7 +891,7 @@ bucket_getstate(Bucket *self, PyObject *args) ...@@ -891,7 +891,7 @@ bucket_getstate(Bucket *self, PyObject *args)
UNLESS (o) goto err; UNLESS (o) goto err;
PyTuple_SET_ITEM(items, l, o); PyTuple_SET_ITEM(items, l, o);
l++; l++;
COPY_VALUE_TO_OBJECT(o, self->values[i]); COPY_VALUE_TO_OBJECT(o, self->values[i]);
UNLESS (o) goto err; UNLESS (o) goto err;
PyTuple_SET_ITEM(items, l, o); PyTuple_SET_ITEM(items, l, o);
...@@ -909,11 +909,11 @@ bucket_getstate(Bucket *self, PyObject *args) ...@@ -909,11 +909,11 @@ bucket_getstate(Bucket *self, PyObject *args)
} }
} }
if (self->next) if (self->next)
ASSIGN(items, Py_BuildValue("OO", items, self->next)); ASSIGN(items, Py_BuildValue("OO", items, self->next));
else else
ASSIGN(items, Py_BuildValue("(O)", items)); ASSIGN(items, Py_BuildValue("(O)", items));
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
PER_ACCESSED(self); PER_ACCESSED(self);
...@@ -953,10 +953,10 @@ _bucket_setstate(Bucket *self, PyObject *args) ...@@ -953,10 +953,10 @@ _bucket_setstate(Bucket *self, PyObject *args)
Py_DECREF(self->next); Py_DECREF(self->next);
self->next=0; self->next=0;
} }
if (len > self->size) if (len > self->size)
{ {
UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*len)) UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*len))
return -1; return -1;
UNLESS (values=PyRealloc(self->values, sizeof(VALUE_TYPE)*len)) UNLESS (values=PyRealloc(self->values, sizeof(VALUE_TYPE)*len))
return -1; return -1;
...@@ -964,7 +964,7 @@ _bucket_setstate(Bucket *self, PyObject *args) ...@@ -964,7 +964,7 @@ _bucket_setstate(Bucket *self, PyObject *args)
self->values=values; self->values=values;
self->size=len; self->size=len;
} }
for (i=0, l=0; i<len; i++) for (i=0, l=0; i<len; i++)
{ {
k=PyTuple_GET_ITEM(items, l); k=PyTuple_GET_ITEM(items, l);
...@@ -1001,7 +1001,7 @@ bucket_setstate(Bucket *self, PyObject *args) ...@@ -1001,7 +1001,7 @@ bucket_setstate(Bucket *self, PyObject *args)
UNLESS (PyArg_ParseTuple(args, "O", &args)) return NULL; UNLESS (PyArg_ParseTuple(args, "O", &args)) return NULL;
PER_PREVENT_DEACTIVATION(self); PER_PREVENT_DEACTIVATION(self);
r=_bucket_setstate(self, args); r=_bucket_setstate(self, args);
PER_ALLOW_DEACTIVATION(self); PER_ALLOW_DEACTIVATION(self);
PER_ACCESSED(self); PER_ACCESSED(self);
...@@ -1051,7 +1051,7 @@ _bucket__p_resolveConflict(PyObject *ob_type, PyObject *s[3]) ...@@ -1051,7 +1051,7 @@ _bucket__p_resolveConflict(PyObject *ob_type, PyObject *s[3])
PyObject *r=0, *a; PyObject *r=0, *a;
Bucket *b[3]; Bucket *b[3];
int i; int i;
for (i=0; i < 3; i++) for (i=0; i < 3; i++)
{ {
if ((b[i]=(Bucket*)PyObject_CallObject(OBJECT(ob_type), NULL))) if ((b[i]=(Bucket*)PyObject_CallObject(OBJECT(ob_type), NULL)))
...@@ -1197,7 +1197,7 @@ bucket_repr(Bucket *self) ...@@ -1197,7 +1197,7 @@ bucket_repr(Bucket *self)
static PyObject *format; static PyObject *format;
PyObject *r, *t; PyObject *r, *t;
UNLESS (format) UNLESS (format=PyString_FromString(MOD_NAME_PREFIX "Bucket(%s)")) UNLESS (format) UNLESS (format=PyString_FromString(MOD_NAME_PREFIX "Bucket(%s)"))
return NULL; return NULL;
UNLESS (t=PyTuple_New(1)) return NULL; UNLESS (t=PyTuple_New(1)) return NULL;
UNLESS (r=bucket_items(self,NULL)) goto err; UNLESS (r=bucket_items(self,NULL)) goto err;
...@@ -1231,26 +1231,26 @@ static PyExtensionClass BucketType = { ...@@ -1231,26 +1231,26 @@ static PyExtensionClass BucketType = {
(reprfunc)0, /*tp_str*/ (reprfunc)0, /*tp_str*/
(getattrofunc)0, /*tp_getattro*/ (getattrofunc)0, /*tp_getattro*/
0, /*tp_setattro*/ 0, /*tp_setattro*/
/* Space for future expansion */ /* Space for future expansion */
0L,0L, 0L,0L,
"Mapping type implemented as sorted list of items", "Mapping type implemented as sorted list of items",
METHOD_CHAIN(Bucket_methods), METHOD_CHAIN(Bucket_methods),
EXTENSIONCLASS_BASICNEW_FLAG EXTENSIONCLASS_BASICNEW_FLAG
#ifdef PERSISTENT #ifdef PERSISTENT
| PERSISTENT_TYPE_FLAG | PERSISTENT_TYPE_FLAG
#endif #endif
| EXTENSIONCLASS_NOINSTDICT_FLAG, | EXTENSIONCLASS_NOINSTDICT_FLAG,
}; };
static int static int
nextBucket(SetIteration *i) nextBucket(SetIteration *i)
{ {
if (i->position >= 0) if (i->position >= 0)
{ {
UNLESS(PER_USE(BUCKET(i->set))) return -1; UNLESS(PER_USE(BUCKET(i->set))) return -1;
if (i->position) if (i->position)
{ {
DECREF_KEY(i->key); DECREF_KEY(i->key);
...@@ -1274,6 +1274,6 @@ nextBucket(SetIteration *i) ...@@ -1274,6 +1274,6 @@ nextBucket(SetIteration *i)
PER_ALLOW_DEACTIVATION(BUCKET(i->set)); PER_ALLOW_DEACTIVATION(BUCKET(i->set));
} }
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