[Zodb-checkins] CVS: Zope/lib/python/persistent - cPickleCache.c:1.90

Jeremy Hylton jeremy at zope.com
Tue Mar 2 10:37:39 EST 2004


Update of /cvs-repository/Zope/lib/python/persistent
In directory cvs.zope.org:/tmp/cvs-serv3178/lib/python/persistent

Modified Files:
	cPickleCache.c 
Log Message:
Call _p_deactivate() instead of indirecting through _p_changed.


=== Zope/lib/python/persistent/cPickleCache.c 1.89 => 1.90 ===
--- Zope/lib/python/persistent/cPickleCache.c:1.89	Thu Feb 19 13:13:35 2004
+++ Zope/lib/python/persistent/cPickleCache.c	Tue Mar  2 10:37:38 2004
@@ -1,4 +1,4 @@
-/*****************************************************************************
+ /*****************************************************************************
 
   Copyright (c) 2001, 2002 Zope Corporation and Contributors.
   All Rights Reserved.
@@ -142,16 +142,22 @@
     ((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
 
 static int
-scan_gc_items(ccobject *self,int target)
+scan_gc_items(ccobject *self, int target)
 {
     /* This function must only be called with the ring lock held,
        because it places a non-object placeholder in the ring.
     */
 
     cPersistentObject *object;
-    int error;
     CPersistentRing placeholder;
     CPersistentRing *here = self->ring_home.r_next;
+    static PyObject *_p_deactivate;
+
+    if (!_p_deactivate) {
+	_p_deactivate = PyString_InternFromString("_p_deactivate");
+	if (!_p_deactivate)
+	    return -1;
+    }
 
     /* Scan through the ring until we either find the ring_home (i.e. start
      * of the ring, or we've ghosted enough objects to reach the target
@@ -175,6 +181,7 @@
         if (self->non_ghost_count <= target)
             return 0;
         else if (object->state == cPersistent_UPTODATE_STATE) {
+	    PyObject *meth, *error;
             /* deactivate it. This is the main memory saver. */
 
             /* Add a placeholder; a dummy node in the ring.  We need
@@ -192,9 +199,12 @@
             here->r_next->r_prev = &placeholder;
             here->r_next = &placeholder;
 
-            /* In Python, "obj._p_changed = None" spells, ghostify */
-            error = PyObject_SetAttr((PyObject *)object, py__p_changed,
-				     Py_None);
+	    /* Call _p_deactivate(), which may be overridden. */
+	    meth = PyObject_GetAttr((PyObject *)object, _p_deactivate);
+	    if (!meth)
+		return -1;
+	    error = PyObject_CallObject(meth, NULL);
+	    Py_DECREF(meth);
 
             /* unlink the placeholder */
             placeholder.r_next->r_prev = placeholder.r_prev;
@@ -202,8 +212,9 @@
 
             here = placeholder.r_next;
 
-            if (error)
+            if (!error)
                 return -1; /* problem */
+	    Py_DECREF(error);
         }
         else
             here = here->r_next;




More information about the Zodb-checkins mailing list