[Zope3-checkins] CVS: Zope3/src/zope/app/container - _zope_app_container_contained.c:1.2.10.2

Jim Fulton jim at zope.com
Fri Jan 16 10:44:09 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv19071/src/zope/app/container

Modified Files:
      Tag: zope3-zodb3-devel-branch
	_zope_app_container_contained.c 
Log Message:
Various changes to get tests passing.


=== Zope3/src/zope/app/container/_zope_app_container_contained.c 1.2.10.1 => 1.2.10.2 ===
--- Zope3/src/zope/app/container/_zope_app_container_contained.c:1.2.10.1	Fri Jan  9 17:23:48 2004
+++ Zope3/src/zope/app/container/_zope_app_container_contained.c	Fri Jan 16 10:43:30 2004
@@ -12,9 +12,28 @@
 #
 ############################################################################*/
 
+/* Contained Proxy Base class
+
+ Contained proxies provide __parent__ and __name__ attributes for
+ objects without them.
+
+ There is something strange and, possibly cool, going on here, wrt
+ persistence.  To reuse the base proxy implementation we don't treat
+ the proxied object as part of the persistent state of the proxy.
+ This means that the proxy still operates as a proxy even if it is a
+ ghost.  
+
+ The proxy will only be unghostified if you need to access one of the
+ attributes provided by the proxy.
+
+ */
+
+
 #include "Python.h"
 #include "persistent/cPersistence.h"
 
+static PyObject *str_p_deactivate;
+
 typedef struct {
   cPersistent_HEAD               
   PyObject *po_serial;            
@@ -31,6 +50,7 @@
     PyObject *(*getobject)(PyObject *proxy);
 } ProxyInterface;
 
+#define OBJECT(O) ((PyObject*)(O))
 #define Proxy_GET_OBJECT(ob)   (((ProxyObject *)(ob))->proxy_object)
 
 /* Supress inclusion of the original proxy.h */
@@ -123,12 +143,17 @@
 static PyObject *
 CP_reduce(ProxyObject *self)
 {
-  return Py_BuildValue("O(O)(OO)",
-                       self->ob_type,
-                       self->proxy_object,
-                       self->__parent__ ? self->__parent__ : Py_None,
-                       self->__name__   ? self->__name__   : Py_None
-                       );
+  PyObject *result;
+  if (! PER_USE(self))
+    return NULL;
+  result = Py_BuildValue("O(O)(OO)",
+                         self->ob_type,
+                         self->proxy_object,
+                         self->__parent__ ? self->__parent__ : Py_None,
+                         self->__name__   ? self->__name__   : Py_None
+                         );
+  PER_ALLOW_DEACTIVATION(self);
+  return result;
 }
 
 static PyObject *
@@ -138,48 +163,25 @@
 }
 
 static PyObject *
-CP__p_deactivate(ProxyObject *self, PyObject *args, PyObject *keywords)
+CP__p_deactivate(ProxyObject *self)
 {
-    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;
-	}
-    }
+  PyObject *result;
 
-    if (self->jar && self->oid) {
-	ghostify = self->state == cPersistent_UPTODATE_STATE;
-	if (!ghostify && force) {
-	    if (PyObject_IsTrue(force))
-		ghostify = 1;
-	    if (PyErr_Occurred())
-		return NULL;
-	}
-	if (ghostify) {
-            Py_XDECREF(self->__parent__);
-            self->__parent__ = NULL;
-            Py_XDECREF(self->__name__);
-            self->__name__ = NULL;
+  result = PyObject_CallMethodObjArgs(OBJECT(cPersistenceType), 
+                                      str_p_deactivate,
+                                      self, NULL);
+  if (result == NULL)
+    return NULL;
 
-	    self->state = cPersistent_GHOST_STATE;
-	}
+  if (self->jar && self->oid && self->state == cPersistent_UPTODATE_STATE)
+    {
+      Py_XDECREF(self->__parent__);
+      self->__parent__ = NULL;
+      Py_XDECREF(self->__name__);
+      self->__name__ = NULL;
     }
 
-    Py_INCREF(Py_None);
-    return Py_None;
+    return result;
 }
 
 
@@ -195,7 +197,7 @@
    "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, 
+  {"_p_deactivate", (PyCFunction)CP__p_deactivate, METH_NOARGS, 
    "Deactivate the object."},
   {NULL, NULL},
 };
@@ -232,6 +234,7 @@
 static int
 CP_clear(ProxyObject *self)
 {
+  PyObject *tmp;
   /* XXXX Drop references that may have created reference
      cycles. Immutable objects do not have to define this method
      since they can never directly create reference cycles. Note
@@ -243,14 +246,13 @@
   if (cPersistenceType->tp_clear != NULL)
     cPersistenceType->tp_clear((PyObject*)self);
 
-  Py_XDECREF(self->po_serial);
-  self->po_serial = NULL;
-  Py_XDECREF(self->proxy_object);
-  self->proxy_object = NULL;
-  Py_XDECREF(self->__parent__);
-  self->__parent__ = NULL;
-  Py_XDECREF(self->__name__);
-  self->__name__ = NULL;
+#define CLEAR(O) tmp = O; O = NULL; Py_XDECREF(tmp);
+  
+  CLEAR(self->po_serial);
+  CLEAR(self->proxy_object);
+  CLEAR(self->__parent__);
+  CLEAR(self->__name__);
+
   return 0;
 }
 
@@ -272,6 +274,10 @@
 init_zope_app_container_contained(void)
 {
   PyObject *m;
+
+  str_p_deactivate = PyString_FromString("_p_deactivate");
+  if (str_p_deactivate == NULL)
+    return;
         
   /* Try to fake out compiler nag function */
   if (0) init_zope_proxy_proxy();




More information about the Zope3-Checkins mailing list