[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BucketTemplate.c:1.1.2.3

Jeremy Hylton jeremy@zope.com
Wed, 27 Feb 2002 00:46:45 -0500


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv11780

Modified Files:
      Tag: Zope-3x-branch
	BucketTemplate.c 
Log Message:
Reformat Bucket_grow(), bucket_split(), Bucket_nextBucket(),
    Bucket_deleteNextBucket(), bucket_keys(), bucket_byValue(),
    _bucket_clear(), bucket__p_deactivate(), bucket_getstate(),
    _bucket_setstate(), bucket_setstate(), bucket_has_key(),
    bucket_getm(), bucket_dealloc().

Add some comments.
Change some METH_VARARGS to METH_O / METH_NOARGS.
    
(In search of refcount bugs, none found yet.)



=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.1.2.2 => 1.1.2.3 === (566/666 lines abridged)
 Bucket_grow(Bucket *self, int noval)
 {
-  KEY_TYPE *keys;
-  VALUE_TYPE *values;
+    KEY_TYPE *keys;
+    VALUE_TYPE *values;
 
-  if (self->size)
-    {
-      UNLESS (keys=PyRealloc(self->keys, sizeof(KEY_TYPE)*self->size*2))
-        return -1;
-      
-      UNLESS (noval)
-        {
-          UNLESS (values=PyRealloc(self->values,
-                                   sizeof(VALUE_TYPE)*self->size*2))
-            return -1;
-          self->values=values;
-        }
-      self->keys=keys;
-      self->size*=2;
-    }
-  else
-    {
-      UNLESS (self->keys=PyMalloc(sizeof(KEY_TYPE)*MIN_BUCKET_ALLOC))
-        return -1;
-      UNLESS (noval || 
-              (self->values=PyMalloc(sizeof(VALUE_TYPE)*MIN_BUCKET_ALLOC))
-              )
-        return -1;
-      self->size=MIN_BUCKET_ALLOC;
+    if (self->size) {
+	keys = PyRealloc(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);
+	    if (values == NULL)
+		return -1;
+	    self->values=values;
+	}
+	self->keys = keys;
+	self->size *= 2;
+    } else {
+	self->keys = PyMalloc(sizeof(KEY_TYPE) * MIN_BUCKET_ALLOC);
+	if (self->keys == NULL)
+	    return -1;
+	if (!noval) {
+	    self->values = PyMalloc(sizeof(VALUE_TYPE) * MIN_BUCKET_ALLOC);

[-=- -=- -=- 566 lines omitted -=- -=- -=-]

 
-  return _bucket__p_resolveConflict(OBJECT(self->ob_type), s);
+    return _bucket__p_resolveConflict((PyObject *)self->ob_type, s);
 }
 #endif
 
 static struct PyMethodDef Bucket_methods[] = {
-  {"__getstate__", (PyCFunction) bucket_getstate,	METH_VARARGS,
+  {"__getstate__", (PyCFunction) bucket_getstate,	METH_NOARGS,
    "__getstate__() -- Return the picklable state of the object"},
-  {"__setstate__", (PyCFunction) bucket_setstate,	METH_VARARGS,
+  {"__setstate__", (PyCFunction) bucket_setstate,	METH_O,
    "__setstate__() -- Set the state of the object"},
   {"keys",	(PyCFunction) bucket_keys,	METH_VARARGS,
      "keys([min, max]) -- Return the keys"},
-  {"has_key",	(PyCFunction) bucket_has_key,	METH_VARARGS,
+  {"has_key",	(PyCFunction) bucket_has_key,	METH_O,
      "has_key(key) -- Test whether the bucket contains the given key"},
   {"clear",	(PyCFunction) bucket_clear,	METH_VARARGS,
    "clear() -- Remove all of the items from the bucket"},
@@ -1120,7 +1129,7 @@
      "values([min, max]) -- Return the values"},
   {"items",	(PyCFunction) bucket_items,	METH_VARARGS,
      "items([min, max])) -- Return the items"},
-  {"byValue",	(PyCFunction) bucket_byValue,	METH_VARARGS,
+  {"byValue",	(PyCFunction) bucket_byValue,	METH_O,
    "byValue(min) -- "
    "Return value-keys with values >= min and reverse sorted by values"
   },
@@ -1145,6 +1154,8 @@
     if (!PyArg_ParseTuple(args, "|O:" MOD_NAME_PREFIX "Bucket", &v))
 	return -1;
 
+/*    fprintf(stderr, "Bucket_init %X\n", self); */
+
     if (v)
 	return update_from_seq(self, v);
     else
@@ -1154,8 +1165,9 @@
 static void
 bucket_dealloc(Bucket *self)
 {
-  _bucket_clear(self);
-  PyPersist_TYPE->tp_dealloc((PyObject *)self);
+/*    fprintf(stderr, "bucket_dealloc %X\n", self); */
+    _bucket_clear(self);
+    PyPersist_TYPE->tp_dealloc((PyObject *)self);
 }
 
 static int