[Zodb-checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.1.2.16
Jeremy Hylton
jeremy@zope.com
Thu, 6 Jun 2002 14:26:38 -0400
Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv20858
Modified Files:
Tag: Zope-3x-branch
cPersistence.c
Log Message:
Fix invocation of _p_deactivate().
The old version of the code was always calling the base persistence
_p_deactivate() -- spelled persist_deactivate in C. If type or class
had a customize _p_deactivate() it was ignored. Errors that occurred
during the call where also ignored.
Fix the cPersistence machinery to lookup _p_deactivate() on the
object. XXX Should we try to optimize this newly slower code?
Make sure the BTrees _p_deactivate() methods are defined using
METH_NOARGS and are formatted consistently.
=== Zope3/lib/python/Persistence/cPersistence.c 1.1.2.15 => 1.1.2.16 ===
}
+static int
+_p_deactivate(PyPersistObject *self)
+{
+ static PyObject *t = NULL;
+ PyObject *func, *r;
+ if (!t) {
+ t = PyTuple_New(0);
+ if (!t)
+ return 0;
+ }
+ func = PyObject_GetAttrString((PyObject *)self, "_p_deactivate");
+ if (!func)
+ return 0;
+ r = PyObject_Call(func, t, NULL);
+ Py_DECREF(func);
+ if (!r)
+ return 0;
+ else {
+ Py_DECREF(r);
+ return 1;
+ }
+}
+
#define CHANGED_NONE 0
#define CHANGED_FALSE 1
#define CHANGED_TRUE 2
@@ -433,16 +456,18 @@
self->po_state = UPTODATE;
} else if (newstate == CHANGED_DELETE) {
/* Force the object to UPTODATE state to guarantee that
- persist_deactivate() will turn it into a ghost.
+ _p_deactivate() will turn it into a ghost.
*/
self->po_state = UPTODATE;
- persist_deactivate(self);
+ if (!_p_deactivate(self))
+ return -1;
} else if (self->po_state == UPTODATE) {
/* The final case is for CHANGED_NONE, which is only
meaningful when the object is already in the up-to-date state.
In this case, turn the object into a ghost.
*/
- persist_deactivate(self);
+ if (!_p_deactivate(self))
+ return -1;
}
return 0;
@@ -531,7 +556,7 @@
if (self->po_state == GHOST) {
self->po_state = CHANGED;
if (_PyPersist_Load((PyPersistBaseObject *)self) == NULL) {
- persist_deactivate(self);
+ _p_deactivate(self);
self->po_state = GHOST;
return NULL;
} else