Commit 092a0b5e authored by matt@zope.com's avatar matt@zope.com

Raise ZODB.POSException.ConflictError inside of resolveConflict routines

instead of any other error that may be raised.
parent 1c28b1f0
......@@ -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))
......@@ -340,7 +341,7 @@ static char BTree_module_documentation[] =
"\n"
MASTER_ID
BTREEITEMSTEMPLATE_C
"$Id: BTreeModuleTemplate.c,v 1.11 2001/04/03 15:02:17 jim Exp $\n"
"$Id: BTreeModuleTemplate.c,v 1.12 2001/06/20 14:48:51 matt Exp $\n"
BTREETEMPLATE_C
BUCKETTEMPLATE_C
KEYMACROS_H
......@@ -355,7 +356,7 @@ BTREEITEMSTEMPLATE_C
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 @@ INITMODULE (void)
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;
......@@ -409,7 +427,7 @@ INITMODULE (void)
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__",
PyString_FromString("$Revision: 1.11 $"));
PyString_FromString("$Revision: 1.12 $"));
PyExtensionClass_Export(d,MOD_NAME_PREFIX "Bucket", BucketType);
PyExtensionClass_Export(d,MOD_NAME_PREFIX "BTree", BTreeType);
......
......@@ -83,7 +83,7 @@
****************************************************************************/
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.16 2001/04/03 15:02:17 jim Exp $\n"
#define BTREETEMPLATE_C "$Id: BTreeTemplate.c,v 1.17 2001/06/20 14:48:51 matt Exp $\n"
/*
** _BTree_get
......@@ -862,7 +862,19 @@ BTree__p_resolveConflict(BTree *self, PyObject *args)
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;
}
......
......@@ -82,7 +82,7 @@
****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.14 2001/04/03 15:02:17 jim Exp $\n"
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.15 2001/06/20 14:48:51 matt Exp $\n"
/*
** _bucket_get
......@@ -1120,10 +1120,23 @@ static PyObject *
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
......
......@@ -83,7 +83,7 @@
****************************************************************************/
#define MERGETEMPLATE_C "$Id: MergeTemplate.c,v 1.5 2001/04/03 15:02:17 jim Exp $\n"
#define MERGETEMPLATE_C "$Id: MergeTemplate.c,v 1.6 2001/06/20 14:48:51 matt Exp $\n"
/****************************************************************************
Set operations
......@@ -110,7 +110,8 @@ merge_error(int p1, int p2, int p3, int reason)
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);
......
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