[Zope-Checkins] CVS: Zope2 - BucketTemplate.c:1.6.2.10

Jim Fulton jim@digiciool.com
Wed, 14 Mar 2001 09:54:13 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/BTrees
In directory korak:/tmp/cvs-serv610

Modified Files:
      Tag: Catalog-BTrees-Integration
	BucketTemplate.c 
Log Message:
Added conflict resolution for small buckets and sets.




--- Updated File BucketTemplate.c in package Zope2 --
--- BucketTemplate.c	2001/03/12 17:30:15	1.6.2.9
+++ BucketTemplate.c	2001/03/14 14:54:13	1.6.2.10
@@ -927,7 +927,7 @@
   KEY_TYPE *keys;
   VALUE_TYPE *values;
 
-  UNLESS (PyArg_ParseTuple(args, "O|O!", &items, self->ob_type, &next))
+  UNLESS (PyArg_ParseTuple(args, "O|O", &items, &next))
     return -1;
 
   if ((len=PyTuple_Size(items)) < 0) return -1;
@@ -1031,22 +1031,22 @@
 }
 
 #ifdef PERSISTENT
-static void merge_error();
+static PyObject *merge_error(int p1, int p2, int p3, int reason);
 static PyObject *bucket_merge(PyObject *s1, PyObject *s2, PyObject *s3);
 
 static PyObject *
-bucket__p_resolveConflict(Bucket *self, PyObject *args)
+_bucket__p_resolveConflict(PyObject *ob_type, PyObject *s[3])
 {
-  PyObject *s[3], *r=0;
+  PyObject *r=0;
   Bucket *b[3];
   int i;
-
-  UNLESS(PyArg_ParseTuple(args, "OOO", &s[0], &s[1], &s[2])) return NULL;
   
   for (i=0; i < 3; i++)
     {
-      if (b[i]=(Bucket*)PyObject_CallObject(OBJECT(self->ob_type), NULL))
+      if (b[i]=(Bucket*)PyObject_CallObject(OBJECT(ob_type), NULL))
         {
+          if (s[i] == Py_None)  /* None is equivalent to empty, for BTrees */
+            continue;
           ASSIGN(r, PyObject_GetAttr(OBJECT(b[i]), __setstate___str));
           if (r) ASSIGN(r, PyObject_CallFunction(r, "(O)", s[i]));
           if (r) continue;
@@ -1063,7 +1063,7 @@
 
   if (b[0]->next != b[1]->next || b[0]->next != b[2]->next)
     {
-      merge_error();
+      merge_error(-1, -1, -1, -1);
       goto err;
     }
 
@@ -1076,6 +1076,16 @@
 
   return r;
 }
+
+static PyObject *
+bucket__p_resolveConflict(Bucket *self, PyObject *args)
+{
+  PyObject *s[3];
+
+  UNLESS(PyArg_ParseTuple(args, "OOO", &s[0], &s[1], &s[2])) return NULL;
+
+  return _bucket__p_resolveConflict(OBJECT(self->ob_type), s);
+}
 #endif
 
 static struct PyMethodDef Bucket_methods[] = {
@@ -1112,7 +1122,7 @@
    "Return the default (or None) if the key is not found."
   },
 #ifdef PERSISTENT
-  {"  _p_resolveConflict", (PyCFunction) bucket__p_resolveConflict, METH_VARARGS,
+  {"_p_resolveConflict", (PyCFunction) bucket__p_resolveConflict, METH_VARARGS,
    "_p_resolveConflict() -- Reinitialize from a newly created copy"},
   {"_p_deactivate", (PyCFunction) bucket__p_deactivate, METH_VARARGS,
    "_p_deactivate() -- Reinitialize from a newly created copy"},