[Zope-Checkins] CVS: Zope/lib/python/BTrees - BTreeItemsTemplate.c:1.12

Tim Peters tim.one@comcast.net
Sun, 9 Jun 2002 18:22:50 -0400


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

Modified Files:
	BTreeItemsTemplate.c 
Log Message:
nextBTreeItems() and nextTreeSetItems():  unlike the other set iteration
"next" functions, these can return a PER_USE() error *after* decrefing
the keys and values left over from the last call.  But they don't mark
the iteration as terminated, so finiSetIteration() will also try to
decref the leftovers.  The fix is to mark the iteration as terminated
when these functions fail.


=== Zope/lib/python/BTrees/BTreeItemsTemplate.c 1.11 => 1.12 ===
 
           currentbucket = BUCKET(ITEMS(i->set)->currentbucket);
-
-          UNLESS(PER_USE(currentbucket)) return -1;
+          UNLESS(PER_USE(currentbucket))
+            {
+              /* Mark iteration terminated, so that finiSetIteration doesn't
+               * try to redundantly decref the key and value
+               */
+              i->position = -1;
+              return -1;
+            }
 
           COPY_KEY(i->key, currentbucket->keys[ITEMS(i->set)->currentoffset]);
           INCREF_KEY(i->key);
@@ -555,8 +561,14 @@
           Bucket *currentbucket;
 
           currentbucket = BUCKET(ITEMS(i->set)->currentbucket);
-
-          UNLESS(PER_USE(currentbucket)) return -1;
+          UNLESS(PER_USE(currentbucket))
+            {
+              /* Mark iteration terminated, so that finiSetIteration doesn't
+               * try to redundantly decref the key and value
+               */
+              i->position = -1;
+              return -1;
+            }
 
           COPY_KEY(i->key, currentbucket->keys[ITEMS(i->set)->currentoffset]);
           INCREF_KEY(i->key);