[Zodb-checkins] SVN: ZODB/trunk/ Merge rev 37244 from 3.4 branch.

Tim Peters tim.one at comcast.net
Mon Jul 18 15:27:28 EDT 2005


Log message for revision 37245:
  Merge rev 37244 from 3.4 branch.
  
  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/trunk/NEWS.txt
  U   ZODB/trunk/src/BTrees/BucketTemplate.c
  U   ZODB/trunk/src/BTrees/tests/testBTrees.py

-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt	2005-07-18 19:24:04 UTC (rev 37244)
+++ ZODB/trunk/NEWS.txt	2005-07-18 19:27:28 UTC (rev 37245)
@@ -117,6 +117,11 @@
 BTrees
 ------
 
+- (3.5.a5) 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.5a4) Collector 1831.  The BTree ``minKey()`` and ``maxKey()`` methods
   gave a misleading message if no key satisfying the constraints existed in a
   non-empty tree.
@@ -245,6 +250,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/trunk/src/BTrees/BucketTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/BucketTemplate.c	2005-07-18 19:24:04 UTC (rev 37244)
+++ ZODB/trunk/src/BTrees/BucketTemplate.c	2005-07-18 19:27:28 UTC (rev 37245)
@@ -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/trunk/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/trunk/src/BTrees/tests/testBTrees.py	2005-07-18 19:24:04 UTC (rev 37244)
+++ ZODB/trunk/src/BTrees/tests/testBTrees.py	2005-07-18 19:27:28 UTC (rev 37245)
@@ -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