[Zope3-checkins] CVS: Zope3/src/zope/app/container -
_zope_app_container_contained.c:1.1.2.2
Jim Fulton
jim at zope.com
Wed Sep 17 18:27:34 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv22584
Modified Files:
Tag: parentgeddon-branch
_zope_app_container_contained.c
Log Message:
Fixed a number of bugs in handling weakrefs and inherited persistent
data.
=== Zope3/src/zope/app/container/_zope_app_container_contained.c 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/container/_zope_app_container_contained.c:1.1.2.1 Wed Sep 17 09:00:48 2003
+++ Zope3/src/zope/app/container/_zope_app_container_contained.c Wed Sep 17 18:27:33 2003
@@ -138,6 +138,58 @@
return CP_reduce(self);
}
+static PyObject *
+CP__p_deactivate(ProxyObject *self, PyObject *args, PyObject *keywords)
+{
+ int ghostify = 1;
+ PyObject *force = NULL;
+
+ if (args && PyTuple_GET_SIZE(args) > 0) {
+ PyErr_SetString(PyExc_TypeError,
+ "_p_deactivate takes not positional arguments");
+ return NULL;
+ }
+ if (keywords) {
+ int size = PyDict_Size(keywords);
+ force = PyDict_GetItemString(keywords, "force");
+ if (force)
+ size--;
+ if (size) {
+ PyErr_SetString(PyExc_TypeError,
+ "_p_deactivate only accepts keyword arg force");
+ return NULL;
+ }
+ }
+
+ if (self->po_dm && self->po_oid) {
+ ghostify = self->po_state == UPTODATE;
+ if (!ghostify && force) {
+ if (PyObject_IsTrue(force))
+ ghostify = 1;
+ if (PyErr_Occurred())
+ return NULL;
+ }
+ if (ghostify) {
+ PyObject **pdict = _PyObject_GetDictPtr((PyObject *)self);
+ if (pdict && *pdict) {
+ Py_DECREF(*pdict);
+ *pdict = NULL;
+ }
+
+ Py_XDECREF(self->__parent__);
+ self->__parent__ = NULL;
+ Py_XDECREF(self->__name__);
+ self->__name__ = NULL;
+
+ self->po_state = GHOST;
+ }
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
static PyMethodDef
CP_methods[] = {
{"__getstate__", (PyCFunction)CP_getstate, METH_NOARGS,
@@ -150,6 +202,8 @@
"Reduce the object to constituent parts."},
{"__reduce_ex__", (PyCFunction)CP_reduce_ex, METH_O,
"Reduce the object to constituent parts."},
+ {"_p_deactivate", (PyCFunction)CP__p_deactivate, METH_KEYWORDS,
+ "Deactivate the object."},
{NULL, NULL},
};
@@ -168,9 +222,9 @@
static int
CP_traverse(ProxyObject *self, visitproc visit, void *arg)
{
- if (self->po_serial != NULL && visit(self->po_serial, arg) < 0)
+ if (PyPersist_TYPE->tp_traverse((PyObject *)self, visit, arg) < 1)
return -1;
- if (self->po_weaklist != NULL && visit(self->po_weaklist, arg) < 0)
+ if (self->po_serial != NULL && visit(self->po_serial, arg) < 0)
return -1;
if (self->proxy_object != NULL && visit(self->proxy_object, arg) < 0)
return -1;
@@ -193,10 +247,10 @@
collector will call this method if it detects that this
object is involved in a reference cycle.
*/
+ PyPersist_TYPE->tp_clear((PyObject*)self);
+
Py_XDECREF(self->po_serial);
self->po_serial = NULL;
- Py_XDECREF(self->po_weaklist);
- self->po_weaklist = NULL;
Py_XDECREF(self->proxy_object);
self->proxy_object = NULL;
Py_XDECREF(self->__parent__);
@@ -209,6 +263,9 @@
static void
CP_dealloc(ProxyObject *self)
{
+ if (self->po_weaklist != NULL)
+ PyObject_ClearWeakRefs((PyObject *)self);
+
PyObject_GC_UnTrack((PyObject *)self);
CP_clear(self);
self->ob_type->tp_free((PyObject*)self);
More information about the Zope3-Checkins
mailing list