[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeModuleTemplate.c:1.4

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


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv5236

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


=== Zope3/lib/python/Persistence/BTrees/BTreeModuleTemplate.c 1.3 => 1.4 ===
 }
 
-/* Returns a new reference to the bucket before current.
-   Returns NULL and sets IndexError, i on error.
+/* 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)
 {
@@ -273,27 +274,22 @@
         return NULL;
     }
 
-    Py_INCREF(first);
     while (1) {
-	/* XXX Doesn't this leak a reference to first on error? */
+        Bucket *next;
 	PyPersist_INCREF(first);
 	if (!PyPersist_IS_STICKY(first))
 	    return NULL;
-	if (first->next == current) {
-	    PER_ALLOW_DEACTIVATION(first);
-	    PyPersist_SetATime(first);
+        next = first->next;
+        PER_ALLOW_DEACTIVATION(first);
+	PyPersist_SetATime(first);
+
+	if (next == current) {
+	    Py_INCREF(first);
 	    return first;
-        } else if (first->next) {
-	    Bucket *next = first->next;
-	    Py_INCREF(next);
-	    PER_ALLOW_DEACTIVATION(first);
-	    PyPersist_SetATime(first);
-	    Py_DECREF(first);
+        }
+        else if (next)
 	    first = next;
-        } else {
-	    PER_ALLOW_DEACTIVATION(first);
-	    PyPersist_SetATime(first);
-	    Py_DECREF(first);
+        else {
 	    IndexError(i);
 	    return NULL;
         }