SVN: ZODB/trunk/src/persistent/cPersistence. Added a C API for calling readCurrent.

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20100902135539.1E21F941DF__20304.6925053515$1283435745$gmane$org@cvs.zope.org>
Log message for revision 116138:
  Added a C API for calling readCurrent.
  
  (This is indirectly tested by the BTree tests.)
  

Changed:
  U   ZODB/trunk/src/persistent/cPersistence.c
  U   ZODB/trunk/src/persistent/cPersistence.h

-=-
Modified: ZODB/trunk/src/persistent/cPersistence.c
===================================================================
--- ZODB/trunk/src/persistent/cPersistence.c	2010-09-02 13:55:36 UTC (rev 116137)
+++ ZODB/trunk/src/persistent/cPersistence.c	2010-09-02 13:55:38 UTC (rev 116138)
@@ -223,6 +223,29 @@
   return 0;
 }
 
+static int
+readCurrent(cPersistentObject *self)
+{
+  if ((self->state == cPersistent_UPTODATE_STATE ||
+       self->state == cPersistent_STICKY_STATE)
+      && self->jar && self->oid)
+    {
+      static PyObject *s_readCurrent=NULL;
+      PyObject *r;
+
+      if (s_readCurrent == NULL)
+        s_readCurrent = PyString_InternFromString("readCurrent");
+
+      r = PyObject_CallMethodObjArgs(self->jar, s_readCurrent, self, NULL);
+      if (r == NULL)
+        return -1;
+
+      Py_DECREF(r);
+    }
+
+  return 0;
+}
+
 static PyObject *
 Per__p_deactivate(cPersistentObject *self)
 {
@@ -1262,9 +1285,10 @@
   accessed,
   ghostify,
   (intfunctionwithpythonarg)Per_setstate,
-  NULL /* The percachedel slot is initialized in cPickleCache.c when
+  NULL, /* The percachedel slot is initialized in cPickleCache.c when
           the module is loaded.  It uses a function in a different
           shared library. */
+  readCurrent
 };
 
 void

Modified: ZODB/trunk/src/persistent/cPersistence.h
===================================================================
--- ZODB/trunk/src/persistent/cPersistence.h	2010-09-02 13:55:36 UTC (rev 116137)
+++ ZODB/trunk/src/persistent/cPersistence.h	2010-09-02 13:55:38 UTC (rev 116138)
@@ -103,6 +103,7 @@
     void (*ghostify)(cPersistentObject*);
     int (*setstate)(PyObject*);
     percachedelfunc percachedel;
+    int (*readCurrent)(cPersistentObject*);
 } cPersistenceCAPIstruct;
 
 #define cPersistenceType cPersistenceCAPI->pertype
@@ -119,6 +120,9 @@
 
 #define PER_CHANGED(O) (cPersistenceCAPI->changed((cPersistentObject*)(O)))
 
+#define PER_READCURRENT(O, E)                                     \
+  if (cPersistenceCAPI->readCurrent((cPersistentObject*)(O)) < 0) { E; }
+
 #define PER_GHOSTIFY(O) (cPersistenceCAPI->ghostify((cPersistentObject*)(O)))
 
 /* If the object is sticky, make it non-sticky, so that it can be ghostified.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.