[Zope-Checkins] CVS: Zope2 - BucketTemplate.c:1.6.2.9
Jim Fulton
jim@digiciool.com
Mon, 12 Mar 2001 12:30:16 -0500 (EST)
Update of /cvs-repository/Zope2/lib/python/BTrees
In directory korak:/tmp/cvs-serv30010
Modified Files:
Tag: Catalog-BTrees-Integration
BucketTemplate.c
Log Message:
Fixed failure to detect changes in bucket when not storing bucket as
separate database record.
--- Updated File BucketTemplate.c in package Zope2 --
--- BucketTemplate.c 2001/03/04 19:11:09 1.6.2.8
+++ BucketTemplate.c 2001/03/12 17:30:15 1.6.2.9
@@ -184,7 +184,8 @@
** 1 on success with a new value (growth)
*/
static int
-_bucket_set(Bucket *self, PyObject *keyarg, PyObject *v, int unique, int noval)
+_bucket_set(Bucket *self, PyObject *keyarg, PyObject *v,
+ int unique, int noval, int *changed)
{
int min, max, i, l, cmp, copied=1;
KEY_TYPE key;
@@ -215,7 +216,7 @@
return 0;
}
#endif
-
+ if (changed) *changed=1;
DECREF_VALUE(self->values[i]);
COPY_VALUE(self->values[i], value);
INCREF_VALUE(self->values[i]);
@@ -318,7 +319,7 @@
static int
bucket_setitem(Bucket *self, PyObject *key, PyObject *v)
{
- if (_bucket_set(self, key, v, 0, 0) < 0) return -1;
+ if (_bucket_set(self, key, v, 0, 0, 0) < 0) return -1;
return 0;
}
@@ -1029,6 +1030,54 @@
return d;
}
+#ifdef PERSISTENT
+static void merge_error();
+static PyObject *bucket_merge(PyObject *s1, PyObject *s2, PyObject *s3);
+
+static PyObject *
+bucket__p_resolveConflict(Bucket *self, PyObject *args)
+{
+ PyObject *s[3], *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))
+ {
+ ASSIGN(r, PyObject_GetAttr(OBJECT(b[i]), __setstate___str));
+ if (r) ASSIGN(r, PyObject_CallFunction(r, "(O)", s[i]));
+ if (r) continue;
+ }
+ Py_XDECREF(r);
+ while (--i >= 0)
+ {
+ Py_DECREF(b[i]);
+ }
+ return NULL;
+ }
+ Py_DECREF(r);
+ r=NULL;
+
+ if (b[0]->next != b[1]->next || b[0]->next != b[2]->next)
+ {
+ merge_error();
+ goto err;
+ }
+
+ r=bucket_merge(OBJECT(b[0]), OBJECT(b[1]), OBJECT(b[2]));
+
+ err:
+ Py_DECREF(b[0]);
+ Py_DECREF(b[1]);
+ Py_DECREF(b[2]);
+
+ return r;
+}
+#endif
+
static struct PyMethodDef Bucket_methods[] = {
{"__getstate__", (PyCFunction) bucket_getstate, METH_VARARGS,
"__getstate__() -- Return the picklable state of the object"},
@@ -1063,6 +1112,8 @@
"Return the default (or None) if the key is not found."
},
#ifdef PERSISTENT
+ {" _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"},
#endif