[Zope-Checkins] CVS: StandaloneZODB/ZODB - cPickleCache.c:1.45

Jeremy Hylton jeremy@zope.com
Tue, 2 Apr 2002 01:03:40 -0500


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv29272

Modified Files:
	cPickleCache.c 
Log Message:
Substantial reformatting of code for readability and style.

A few substantive changes:

Split internals of cc_ass_sub() into two smaller function
cc_add_item() and cc_del_item(), removing several levels of
indentation in the process.

Fix incorrect check for return value from PyDict_SetItem().


=== StandaloneZODB/ZODB/cPickleCache.c 1.44 => 1.45 === (756/856 lines abridged)
 
 /* define this for extra debugging checks, and lousy performance */
+/* Are any of these checks necessary in production code?  How do we
+   decide when to disable it?
+*/
 #define MUCH_RING_CHECKING 1
 
 /* Do we want 'engine noise'.... abstract debugging output useful for
@@ -121,16 +124,16 @@
 
 #ifdef MUCH_RING_CHECKING
     int safety_counter = self->cache_size*10;
-    if(safety_counter<10000) safety_counter = 10000;
+    if (safety_counter<10000) 
+	safety_counter = 10000;
 #endif
 
-    while(1)
-    {
-        if(check_ring(self,"mid-gc")) return -1;
+    while (1) {
+        if (check_ring(self, "mid-gc")) 
+	    return -1;
 
 #ifdef MUCH_RING_CHECKING
-        if(!safety_counter--)
-        {
+        if (!safety_counter--) {
             /* This loop has been running for a very long time.
                It is possible that someone loaded a very large number of objects,
                and now wants us to blow them all away. However it may
@@ -138,37 +141,35 @@
                long then you really have to doubt it will ever terminate.
                In the MUCH_RING_CHECKING build we prefer to raise an exception
                here */
-            PyErr_SetString(PyExc_RuntimeError,"scan_gc_items safety counter exceeded");
+            PyErr_SetString(PyExc_RuntimeError,
+			    "scan_gc_items safety counter exceeded");
             return -1;
         }
 
-        if(!present_in_ring(self,here))
-        {
-            /* Our current working position is no longer in the ring. Thats bad. */
-            PyErr_SetString(PyExc_RuntimeError,"working position fell out the ring, in scan_gc_items");
+        if (!present_in_ring(self, here)) {
+            /* Our current working position is no longer in the ring. 
+	       That's bad. */ 
+            PyErr_SetString(PyExc_RuntimeError,
+		    "working position fell out the ring, in scan_gc_items");

[-=- -=- -=- 756 lines omitted -=- -=- -=-]

 }
 
-static int check_ring(ccobject *self,const char *context)
+/* XXX This function returns false if everything is okay, which is
+   backwards given its name.  All the tests say:
+
+   if (check_ring(...))
+       return error
+*/
+
+static int 
+check_ring(ccobject *self, const char *context)
 {
 #ifdef MUCH_RING_CHECKING
-    int code=_check_ring(self,context);
-    if(code)
-    {
-        /*printf(stderr,"BROKEN RING (code %d) in %s, size %d\n",code,context,PyDict_Size(self->data));*/
-        PyErr_Format(PyExc_RuntimeError,"broken ring (code %d) in %s, size %d",code,context,PyDict_Size(self->data));
+    int code = _check_ring(self,context);
+    if (code) {
+        PyErr_Format(PyExc_RuntimeError,
+		     "broken ring (code %d) in %s, size %d",
+		     code, context, PyDict_Size(self->data));
         return code;
     }
 #endif
@@ -845,11 +886,11 @@
     CPersistentRing *here = self->ring_home.next;
     while(1)
     {
-        if(here==target)
+        if (here==target)
         {
             return 1;
         }
-        if(here==&self->ring_home)
+        if (here==&self->ring_home)
         {
             /* back to the home position, and we didnt find it */
             return 0;
@@ -897,7 +938,7 @@
   
   UNLESS(self = PyObject_NEW(ccobject, &Cctype)) return NULL;
   self->setklassstate=self->jar=NULL;
-  if((self->data=PyDict_New()))
+  if ((self->data=PyDict_New()))
     {
       self->jar=jar; 
       Py_INCREF(jar);