[Zope-Checkins] CVS: Zope2 - BTreeModuleTemplate.c:1.12 BTreeTemplate.c:1.17 BucketTemplate.c:1.15 MergeTemplate.c:1.6
Matthew T. Kromer
matt@digicool.com
Wed, 20 Jun 2001 10:48:52 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/BTrees
In directory korak.digicool.com:/tmp/cvs-serv8506/lib/python/BTrees
Modified Files:
BTreeModuleTemplate.c BTreeTemplate.c BucketTemplate.c
MergeTemplate.c
Log Message:
Raise ZODB.POSException.ConflictError inside of resolveConflict routines
instead of any other error that may be raised.
--- Updated File BTreeModuleTemplate.c in package Zope2 --
--- BTreeModuleTemplate.c 2001/04/03 15:02:17 1.11
+++ BTreeModuleTemplate.c 2001/06/20 14:48:51 1.12
@@ -115,6 +115,7 @@
static PyObject *sort_str, *reverse_str, *items_str, *__setstate___str;
+static PyObject *ConflictError = NULL;
static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#define ASSIGN(V,E) PyVar_Assign(&(V),(E))
@@ -355,7 +356,7 @@
void
INITMODULE (void)
{
- PyObject *m, *d;
+ PyObject *m, *d, *c;
UNLESS (sort_str=PyString_FromString("sort")) return;
UNLESS (reverse_str=PyString_FromString("reverse")) return;
@@ -385,11 +386,28 @@
TreeSetType.tp_setattro=cPersistenceCAPI->setattro;
}
else return;
+
+ /* Grab the ConflictError class */
+
+ m = PyImport_ImportModule("ZODB.POSException");
+
+ if (m != NULL) {
+ c = PyObject_GetAttrString(m,"ConflictError");
+ if (c != NULL)
+ ConflictError = c;
+ else
+ ConflictError = PyExc_ValueError;
+ Py_DECREF(m);
+ } else ConflictError = PyExc_ValueError;
+
+
#else
BTreeType.tp_getattro=PyExtensionClassCAPI->getattro;
BucketType.tp_getattro=PyExtensionClassCAPI->getattro;
SetType.tp_getattro=PyExtensionClassCAPI->getattro;
TreeSetType.tp_getattro=PyExtensionClassCAPI->getattro;
+
+ ConflictError = PyExc_ValueError; /* MergeTemplate checks anyway */
#endif
BTreeItemsType.ob_type=&PyType_Type;
--- Updated File BTreeTemplate.c in package Zope2 --
--- BTreeTemplate.c 2001/04/03 15:02:17 1.16
+++ BTreeTemplate.c 2001/06/20 14:48:51 1.17
@@ -862,7 +862,19 @@
else
r = _bucket__p_resolveConflict(OBJECT(&SetType), s);
- if (r) ASSIGN(r, Py_BuildValue("((O))", r));
+ if (r) {
+ ASSIGN(r, Py_BuildValue("((O))", r));
+ } else {
+ PyObject *error;
+ PyObject *value;
+ PyObject *traceback;
+ /* Change any errors to ConflictErrors */
+
+ PyErr_Fetch(&error, &value, &traceback);
+ Py_INCREF(ConflictError);
+ Py_XDECREF(error);
+ PyErr_Restore(ConflictError, value, traceback);
+ }
return r;
}
--- Updated File BucketTemplate.c in package Zope2 --
--- BucketTemplate.c 2001/04/03 15:02:17 1.14
+++ BucketTemplate.c 2001/06/20 14:48:51 1.15
@@ -1120,10 +1120,23 @@
bucket__p_resolveConflict(Bucket *self, PyObject *args)
{
PyObject *s[3];
+ PyObject *result;
UNLESS(PyArg_ParseTuple(args, "OOO", &s[0], &s[1], &s[2])) return NULL;
- return _bucket__p_resolveConflict(OBJECT(self->ob_type), s);
+ result = _bucket__p_resolveConflict(OBJECT(self->ob_type), s);
+
+ /* Change any errors to ConflictErrors */
+ if (result == NULL) {
+ PyObject *error;
+ PyObject *value;
+ PyObject *traceback;
+
+ PyErr_Fetch(&error, &value, &traceback);
+ Py_INCREF(ConflictError);
+ Py_XDECREF(error);
+ PyErr_Restore(ConflictError, value, traceback);
+ }
}
#endif
--- Updated File MergeTemplate.c in package Zope2 --
--- MergeTemplate.c 2001/04/03 15:02:17 1.5
+++ MergeTemplate.c 2001/06/20 14:48:51 1.6
@@ -110,7 +110,8 @@
PyObject *r;
UNLESS (r=Py_BuildValue("iiii", p1, p2, p3, reason)) r=Py_None;
- PyErr_SetObject(PyExc_ValueError, r);
+ if (ConflictError == NULL) ConflictError=PyExc_ValueError;
+ PyErr_SetObject(ConflictError, r);
if (r != Py_None)
{
Py_DECREF(r);