[Zodb-checkins] SVN: ZODB/branches/3.4/ Collector 1843: IISet.keys: bad exception handling.

Tim Peters tim.one at comcast.net
Mon Jul 18 15:24:05 EDT 2005


Log message for revision 37244:
  Collector 1843:  IISet.keys: bad exception handling.
  
  Bucket_rangeSearch():  De-obfuscated the calls to
  Bucket_findRangeEnd(), so that they stop ignoring
  the latter's error returns (a mind-bending combination
  of embedded assignment nested in an UNLESS macro,
  seemingly copy+paste'd so that the error occurred twice).
  

Changed:
  U   ZODB/branches/3.4/NEWS.txt
  U   ZODB/branches/3.4/src/BTrees/BucketTemplate.c
  U   ZODB/branches/3.4/src/BTrees/tests/testBTrees.py

-=-
Modified: ZODB/branches/3.4/NEWS.txt
===================================================================
--- ZODB/branches/3.4/NEWS.txt	2005-07-18 16:29:17 UTC (rev 37243)
+++ ZODB/branches/3.4/NEWS.txt	2005-07-18 19:24:04 UTC (rev 37244)
@@ -114,6 +114,11 @@
 BTrees
 ------
 
+- (3.4.1a6) Collector 1843.  When a non-integer was passed to a method like
+  ``keys()`` of a Bucket or Set with integer keys, an internal error code
+  was overlooked, leading to everything from "delayed errors" to segfaults.
+  Such cases raise TypeError now, as intended.
+
 - (3.4.1a4) Collector 1831.  The BTree ``minKey()`` and ``maxKey()`` methods
   gave a misleading message if no key satisfying the constraints existed in a
   non-empty tree.

Modified: ZODB/branches/3.4/src/BTrees/BucketTemplate.c
===================================================================
--- ZODB/branches/3.4/src/BTrees/BucketTemplate.c	2005-07-18 16:29:17 UTC (rev 37243)
+++ ZODB/branches/3.4/src/BTrees/BucketTemplate.c	2005-07-18 19:24:04 UTC (rev 37244)
@@ -752,10 +752,11 @@
 
     /* Find the low range */
     if (min != Py_None) {
-        UNLESS (rc = Bucket_findRangeEnd(self, min, 1, excludemin, low)) {
-            if (rc < 0) return -1;
+        rc = Bucket_findRangeEnd(self, min, 1, excludemin, low);
+        if (rc < 0)
+            return -1;
+        if (rc == 0)
             goto empty;
-        }
     }
     else {
     	*low = 0;
@@ -768,10 +769,11 @@
 
     /* Find the high range */
     if (max != Py_None) {
-        UNLESS (rc = Bucket_findRangeEnd(self, max, 0, excludemax, high)) {
-            if (rc < 0) return -1;
+        rc = Bucket_findRangeEnd(self, max, 0, excludemax, high);
+        if (rc < 0)
+            return -1;
+        if (rc == 0)
             goto empty;
-	}
     }
     else {
 	*high = self->len - 1;

Modified: ZODB/branches/3.4/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/branches/3.4/src/BTrees/tests/testBTrees.py	2005-07-18 16:29:17 UTC (rev 37243)
+++ ZODB/branches/3.4/src/BTrees/tests/testBTrees.py	2005-07-18 19:24:04 UTC (rev 37244)
@@ -1409,6 +1409,16 @@
 class IISetTest(ExtendedSetTests):
     def setUp(self):
         self.t = IISet()
+
+    # Collector 1843.  Error returns were effectively ignored in
+    # Bucket_rangeSearch(), leading to "delayed" errors, or worse.
+    def testNonIntKeyRaises(self):
+        self.t.insert(1)
+        # This one used to fail to raise the TypeError when it occurred.
+        self.assertRaises(TypeError, self.t.keys, "")
+        # This one used to segfault.
+        self.assertRaises(TypeError, self.t.keys, 0, "")
+
 class IFSetTest(ExtendedSetTests):
     def setUp(self):
         self.t = IFSet()



More information about the Zodb-checkins mailing list