[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeModuleTemplate.c:1.32

Tim Peters tim.one@comcast.net
Mon, 17 Jun 2002 15:21:40 -0400


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

Modified Files:
	BTreeModuleTemplate.c 
Log Message:
PreviousBucket():  Beefed up docs; simplified code; squashed cases where
an error return leaked references.


=== Zope/lib/python/BTrees/BTreeModuleTemplate.c 1.31 => 1.32 ===
 }
 
+/* Returns a new reference to the bucket before current, in the bucket
+ * chain starting at first.
+ * Returns NULL on error.  IndexError(i) may or may not be set then (XXX I
+ * don't know what the intent is, that's just what it does; should be redone).
+ */
 static Bucket *
 PreviousBucket(Bucket *current, Bucket *first, int i)
 {
   if (! first) return NULL;
-  if (first==current)
+  if (first == current)
     {
       IndexError(i);
       return NULL;
     }
 
-  Py_INCREF(first);
   while (1)
     {
-      PER_USE_OR_RETURN(first,NULL);
-      if (first->next==current)
+      Bucket *next;
+      PER_USE_OR_RETURN(first, NULL);
+      next = first->next;
+      PER_ALLOW_DEACTIVATION(first);
+      PER_ACCESSED(first);
+
+      if (next == current)
         {
-          PER_ALLOW_DEACTIVATION(first);
-          PER_ACCESSED(first);
+          Py_INCREF(first);
           return first;
         }
-      else if (first->next)
-        {
-          Bucket *next = first->next;
-          Py_INCREF(next);
-          PER_ALLOW_DEACTIVATION(first);
-          PER_ACCESSED(first);
-          Py_DECREF(first);
-          first=next;
-        }
+      else if (next)
+        first=next;
       else
         {
-          PER_ALLOW_DEACTIVATION(first);
-          PER_ACCESSED(first);
-          Py_DECREF(first);
           IndexError(i);
           return NULL;
         }