[Zodb-checkins] CVS: ZODB3/ZODB - cPickleCache.c:1.77

Jeremy Hylton jeremy@zope.com
Tue, 1 Apr 2003 11:17:50 -0500


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv7892

Modified Files:
	cPickleCache.c 
Log Message:
Remove object_from_oid() which appeared to be mis-used about half the
time.  Instead use std PyDict_GetItem() and incref only when
necessary.


=== ZODB3/ZODB/cPickleCache.c 1.76 => 1.77 ===
--- ZODB3/ZODB/cPickleCache.c:1.76	Tue Apr  1 11:01:54 2003
+++ ZODB3/ZODB/cPickleCache.c	Tue Apr  1 11:17:50 2003
@@ -147,18 +147,6 @@
 
 /* ---------------------------------------------------------------- */
 
-/* somewhat of a replacement for PyDict_GetItem(self->data....
-   however this returns a *new* reference */
-static PyObject *
-object_from_oid(ccobject *self, PyObject *key)
-{
-    PyObject *v = PyDict_GetItem(self->data, key);
-    if (!v) 
-	return NULL;
-    Py_INCREF(v);
-    return v;
-}
-
 #define OBJECT_FROM_RING(SELF, HERE, CTX) \
     ((cPersistentObject *)(((char *)here) - offsetof(cPersistentObject, ring)))
 
@@ -308,7 +296,7 @@
 static void
 _invalidate(ccobject *self, PyObject *key)
 {
-    PyObject *v = object_from_oid(self, key);
+    PyObject *v = PyDict_GetItem(self->data, key);
 
     if (!v)
 	return;
@@ -329,7 +317,6 @@
 	if (PyObject_DelAttr(v, py__p_changed) < 0)
 	    PyErr_Clear();
     }
-    Py_XDECREF(v);
 }
 
 static PyObject *
@@ -379,17 +366,16 @@
     if (!PyArg_ParseTuple(args, "O|O:get", &key, &d)) 
 	return NULL;
 
-    r = (PyObject *)object_from_oid(self, key);
+    r = PyDict_GetItem(self->data, key);
     if (!r) {
 	if (d) {
 	    r = d;
-	    Py_INCREF(r);
 	} else {
 	    PyErr_SetObject(PyExc_KeyError, key);
 	    return NULL;
 	}
     }
-
+    Py_INCREF(r);
     return r;
 }
 
@@ -670,11 +656,12 @@
 {
     PyObject *r;
 
-    r = (PyObject *)object_from_oid(self, key);
+    r = PyDict_GetItem(self->data, key);
     if (r == NULL) {
 	PyErr_SetObject(PyExc_KeyError, key);
 	return NULL;
     }
+    Py_INCREF(r);
 
     return r;
 }
@@ -739,16 +726,14 @@
     }
     Py_DECREF(jar);
 
-    object_again = object_from_oid(self, key);
+    object_again = PyDict_GetItem(self->data, key);
     if (object_again) {
 	if (object_again != v) {
-	    Py_DECREF(object_again);
 	    PyErr_SetString(PyExc_ValueError,
 		    "Can not re-register object under a different oid");
 	    return -1;
 	} else {
 	    /* re-register under the same oid - no work needed */
-	    Py_DECREF(object_again);
 	    return 0;
 	}
     }
@@ -805,7 +790,7 @@
     cPersistentObject *p;
 
     /* unlink this item from the ring */
-    v = (PyObject *)object_from_oid(self, key);
+    v = PyDict_GetItem(self->data, key);
     if (v == NULL)
 	return -1;
 
@@ -831,8 +816,6 @@
 	Py_DECREF((PyObject *)p->cache);
 	p->cache = NULL;
     }
-
-    Py_DECREF(v);
 
     if (PyDict_DelItem(self->data, key) < 0) {
 	PyErr_SetString(PyExc_RuntimeError,