[Zope-Checkins] CVS: ZODB3/persistent - cPersistence.c:1.75.2.2 cPersistence.h:1.27.10.2 cPickleCache.c:1.87.10.1

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


Update of /cvs-repository/ZODB3/persistent
In directory cvs.zope.org:/tmp/cvs-serv19071/src/persistent

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


=== ZODB3/persistent/cPersistence.c 1.75.2.1 => 1.75.2.2 ===
--- ZODB3/persistent/cPersistence.c:1.75.2.1	Fri Jan  9 17:23:24 2004
+++ ZODB3/persistent/cPersistence.c	Fri Jan 16 10:43:28 2004
@@ -59,7 +59,7 @@
 static void ghostify(cPersistentObject*);
 
 /* Load the state of the object, unghostifying it.  Upon success, return 1.
- * If an error occurred, re-ghostify the object and return 0.
+ * If an error occurred, re-ghostify the object and return -1.
  */
 static int
 unghostify(cPersistentObject *self)
@@ -82,7 +82,7 @@
 	r = PyObject_CallMethod(self->jar, "setstate", "O", (PyObject *)self);
         if (r == NULL) {
             ghostify(self);
-            return 0;
+            return -1;
         }
         self->state = cPersistent_UPTODATE_STATE;
         Py_DECREF(r);
@@ -209,6 +209,17 @@
     return Py_None;
 }
 
+static PyObject *
+Per__p_activate(cPersistentObject *self)
+{
+    if (unghostify(self) < 0)
+        return NULL;
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
+
 
 #include "pickle/pickle.c"
 
@@ -230,7 +241,7 @@
 Per__getstate__(cPersistentObject *self)
 {
     /* XXX Should it be an error to call __getstate__() on a ghost? */
-    if (!unghostify(self))
+    if (unghostify(self) < 0)
         return NULL;
 
     /* XXX shouldn't we increment stickyness? */
@@ -241,6 +252,8 @@
 static struct PyMethodDef Per_methods[] = {
   {"_p_deactivate", (PyCFunction)Per__p_deactivate, METH_NOARGS,
    "_p_deactivate() -- Deactivate the object"},
+  {"_p_activate", (PyCFunction)Per__p_activate, METH_NOARGS,
+   "_p_activate() -- Activate the object"},
   {"__getstate__", (PyCFunction)Per__getstate__, METH_NOARGS,
    pickle___getstate__doc },
 
@@ -378,7 +391,7 @@
     s = PyString_AS_STRING(name);
 
     if (*s != '_' || unghost_getattr(s)) {
-	if (!unghostify(self))
+	if (unghostify(self) < 0)
 	    goto Done;
 	accessed(self);
     }
@@ -420,7 +433,7 @@
     s = PyString_AS_STRING(name);
 
     if (strncmp(s, "_p_", 3) != 0) {
-	if (!unghostify(self))
+	if (unghostify(self) < 0)
 	    goto Done;
 	accessed(self);
 	if (strncmp(s, "_v_", 3) != 0
@@ -589,7 +602,7 @@
 {
     PyObject *t, *v;
 
-    if (!unghostify(self))
+    if (unghostify(self) < 0)
 	return NULL;
 
     accessed(self);
@@ -669,7 +682,7 @@
 static int
 Per_setstate(cPersistentObject *self)
 {
-    if (!unghostify(self))
+    if (unghostify(self) < 0)
         return -1;
     self->state = cPersistent_STICKY_STATE;
     return 0;


=== ZODB3/persistent/cPersistence.h 1.27.10.1 => 1.27.10.2 ===
--- ZODB3/persistent/cPersistence.h:1.27.10.1	Fri Jan  9 17:23:24 2004
+++ ZODB3/persistent/cPersistence.h	Fri Jan 16 10:43:28 2004
@@ -75,10 +75,26 @@
 
 #define PER_GHOSTIFY(O) (cPersistenceCAPI->ghostify((cPersistentObject*)(O)))
 
+/* If the object is sticky, make it non-sticky, so that it can be ghostified.
+   The value is not meaningful
+ */
 #define PER_ALLOW_DEACTIVATION(O) ((O)->state==cPersistent_STICKY_STATE && ((O)->state=cPersistent_UPTODATE_STATE))
 
 #define PER_PREVENT_DEACTIVATION(O)  ((O)->state==cPersistent_UPTODATE_STATE && ((O)->state=cPersistent_STICKY_STATE))
 
+/* 
+   Make a persistent object usable from C by:
+
+   - Making sure it is not a ghost
+
+   - Making it sticky.
+
+   IMPORTANT: If you call this and don't call PER_ALLOW_DEACTIVATION, 
+              your object will not be ghostified.
+
+   PER_USE returns a 1 on success and 0 failure, where failure means
+   error.
+ */
 #define PER_USE(O) \
 (((O)->state != cPersistent_GHOST_STATE \
   || (cPersistenceCAPI->setstate((PyObject*)(O)) >= 0)) \


=== ZODB3/persistent/cPickleCache.c 1.87 => 1.87.10.1 ===
--- ZODB3/persistent/cPickleCache.c:1.87	Fri Nov 28 11:44:55 2003
+++ ZODB3/persistent/cPickleCache.c	Fri Jan 16 10:43:28 2004
@@ -107,11 +107,11 @@
    ccobject_head in cPersistence.c */
 typedef struct {
     CACHE_HEAD
-    int klass_count;                         /* count of persistent classes */
-    PyObject *data;                          /* oid -> object dict */
-    PyObject *jar;                           /* Connection object */
-    PyObject *setklassstate;                 /* ??? */
-    int cache_size;                          /* target number of items in cache */
+    int klass_count;                     /* count of persistent classes */
+    PyObject *data;                      /* oid -> object dict */
+    PyObject *jar;                       /* Connection object */
+    PyObject *setklassstate;             /* ??? */
+    int cache_size;                      /* target number of items in cache */
 
     /* Most of the time the ring contains only:
        * many nodes corresponding to persistent objects
@@ -138,7 +138,7 @@
 
 /* ---------------------------------------------------------------- */
 
-#define OBJECT_FROM_RING(SELF, HERE, CTX) \
+#define OBJECT_FROM_RING(SELF, HERE) \
     ((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
 
 static int
@@ -167,7 +167,7 @@
 	   this because the ring lock is held.  We can safely assume
 	   the current ring node is a persistent object now we know it
 	   is not the home */
-        object = OBJECT_FROM_RING(self, here, "scan_gc_items");
+        object = OBJECT_FROM_RING(self, here);
         if (!object)
 	    return -1;
 
@@ -223,7 +223,7 @@
     }
 
     self->ring_lock = 1;
-    if (scan_gc_items(self, target_size)) {
+    if (scan_gc_items(self, target_size) < 0) {
         self->ring_lock = 0;
         return NULL;
     }
@@ -236,7 +236,7 @@
 static PyObject *
 cc_incrgc(ccobject *self, PyObject *args)
 {
-    int n = 1;
+    int obsolete_arg = -999; 
     int starting_size = self->non_ghost_count;
     int target_size = self->cache_size;
 
@@ -250,19 +250,30 @@
             target_size = target_size_2;
     }
 
-    if (!PyArg_ParseTuple(args, "|i:incrgc", &n))
+
+    if (!PyArg_ParseTuple(args, "|i:incrgc", &obsolete_arg))
 	return NULL;
 
+    if (obsolete_arg != -999
+        &&
+        (PyErr_Warn(PyExc_DeprecationWarning,
+                    "No argument expected")
+         < 0))
+        return NULL;
+
     return lockgc(self, target_size);
 }
 
 static PyObject *
 cc_full_sweep(ccobject *self, PyObject *args)
 {
-    int dt = 0;
+    int dt = -999;
+
+    /* XXX This should be deprecated */
+
     if (!PyArg_ParseTuple(args, "|i:full_sweep", &dt))
 	return NULL;
-    if (dt == 0)
+    if (dt == -999)
 	return lockgc(self, 0);
     else
 	return cc_incrgc(self, args);
@@ -271,9 +282,18 @@
 static PyObject *
 cc_minimize(ccobject *self, PyObject *args)
 {
-    int ignored;
+    int ignored = -999;
+
     if (!PyArg_ParseTuple(args, "|i:minimize", &ignored))
 	return NULL;
+
+    if (ignored != -999
+        &&
+        (PyErr_Warn(PyExc_DeprecationWarning,
+                    "No argument expected")
+         < 0))
+        return NULL;
+
     return lockgc(self, 0);
 }
 
@@ -285,6 +305,13 @@
     if (!v)
 	return;
     if (PyType_Check(v)) {
+        /* This looks wrong, but it isn't. We use strong references to types 
+           because they don't have the ring members.
+
+           XXX the result is that we *never* remove classes unless
+           they are modified.
+
+         */
 	if (v->ob_refcnt <= 1) {
 	    self->klass_count--;
 	    if (PyDict_DelItem(self->data, key) < 0)
@@ -417,7 +444,7 @@
     here = self->ring_home.r_next;
     while (here != &self->ring_home) {
         PyObject *v;
-        cPersistentObject *object = OBJECT_FROM_RING(self, here, "cc_items");
+        cPersistentObject *object = OBJECT_FROM_RING(self, here);
 
         if (object == NULL) {
             Py_DECREF(l);
@@ -520,15 +547,14 @@
     {"klass_items", (PyCFunction)cc_klass_items, METH_NOARGS,
      "List (oid, object) pairs of cached persistent classes."},
     {"full_sweep", (PyCFunction)cc_full_sweep, METH_VARARGS,
-     "full_sweep([age]) -- Perform a full sweep of the cache\n\n"
-     "Supported for backwards compatibility.  If the age argument is 0,\n"
-     "behaves like minimize().  Otherwise, behaves like incrgc()."},
+     "full_sweep() -- Perform a full sweep of the cache."},
     {"minimize",	(PyCFunction)cc_minimize, METH_VARARGS,
      "minimize([ignored]) -- Remove as many objects as possible\n\n"
      "Ghostify all objects that are not modified.  Takes an optional\n"
      "argument, but ignores it."},
     {"incrgc", (PyCFunction)cc_incrgc, METH_VARARGS,
-     "incrgc([n]) -- Perform incremental garbage collection\n\n"
+     "incrgc() -- Perform incremental garbage collection\n\n"
+     "This method had been depricated!"
      "Some other implementations support an optional parameter 'n' which\n"
      "indicates a repetition count; this value is ignored."},
     {"invalidate", (PyCFunction)cc_invalidate, METH_O,
@@ -618,7 +644,7 @@
 
     while (self->ring_home.r_next != &self->ring_home) {
 	CPersistentRing *here = self->ring_home.r_next;
-	cPersistentObject *o = OBJECT_FROM_RING(self, here, "cc_clear");
+	cPersistentObject *o = OBJECT_FROM_RING(self, here);
 
 	if (o->cache) {
 	    Py_INCREF(o); /* account for uncounted reference */
@@ -685,7 +711,7 @@
 	return 0;
 
     while (here != &self->ring_home) {
-	cPersistentObject *o = OBJECT_FROM_RING(self, here, "foo");
+	cPersistentObject *o = OBJECT_FROM_RING(self, here);
 	VISIT(o);
 	here = here->r_next;
     }
@@ -722,6 +748,7 @@
     PyObject *oid, *object_again, *jar;
     cPersistentObject *p;
 
+    /* Sanity check the value given to make sure it is allowed in the cache */
     if (PyType_Check(v)) {
         /* Its a persistent class, such as a ZClass. Thats ok. */
     }
@@ -743,12 +770,13 @@
     oid = PyObject_GetAttr(v, py__p_oid);
     if (oid == NULL)
 	return -1;
-    if (!PyString_Check(oid)) {
+    if (! PyString_Check(oid)) {
         PyErr_Format(PyExc_TypeError,
                      "Cached object oid must be a string, not a %s",
 		     oid->ob_type->tp_name);
 	return -1;
     }
+
     /*  we know they are both strings.
      *  now check if they are the same string.
      */




More information about the Zope-Checkins mailing list