SVN: ZODB/branches/3.9/src/ Fixed bug:

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20100920170813.D166B80270D__20055.9615310796$1285002498$gmane$org@cvs.zope.org>
Log message for revision 116669:
  Fixed bug:
  
  - BTree sets and tree sets didn't correctly check values passed to
    update or to constructors, causing Python to exit under certain
    circumstances.
  

Changed:
  U   ZODB/branches/3.9/src/BTrees/SetTemplate.c
  U   ZODB/branches/3.9/src/BTrees/TreeSetTemplate.c
  U   ZODB/branches/3.9/src/BTrees/tests/testBTrees.py
  U   ZODB/branches/3.9/src/CHANGES.txt

-=-
Modified: ZODB/branches/3.9/src/BTrees/SetTemplate.c
===================================================================
--- ZODB/branches/3.9/src/BTrees/SetTemplate.c	2010-09-20 13:02:45 UTC (rev 116668)
+++ ZODB/branches/3.9/src/BTrees/SetTemplate.c	2010-09-20 17:08:13 UTC (rev 116669)
@@ -32,10 +32,9 @@
 static int
 _Set_update(Bucket *self, PyObject *seq)
 {
-    int n = -1;
+    int n=0, ind=0;
     PyObject *iter, *v;
-    int ind;
-
+ 
     iter = PyObject_GetIter(seq);
     if (iter == NULL)
 	return -1;
@@ -55,15 +54,11 @@
 	else
 	    n += ind;
     }
-    /* n starts out at -1, which is the error return value.  If
-       this point is reached, then there is no error.  n must be
-       incremented to account for the initial value of -1 instead of
-       0.
-    */
-    n++;
 
  err:
     Py_DECREF(iter);
+    if (ind < 0)
+      return -1;
     return n;
 }
 

Modified: ZODB/branches/3.9/src/BTrees/TreeSetTemplate.c
===================================================================
--- ZODB/branches/3.9/src/BTrees/TreeSetTemplate.c	2010-09-20 13:02:45 UTC (rev 116668)
+++ ZODB/branches/3.9/src/BTrees/TreeSetTemplate.c	2010-09-20 17:08:13 UTC (rev 116669)
@@ -35,9 +35,8 @@
 static int
 _TreeSet_update(BTree *self, PyObject *seq)
 {
-    int n = -1;
+    int n=0, ind=0;
     PyObject *iter, *v;
-    int ind;
 
     iter = PyObject_GetIter(seq);
     if (iter == NULL)
@@ -58,15 +57,11 @@
 	else
 	    n += ind;
     }
-    /* n starts out at -1, which is the error return value.  If
-       this point is reached, then there is no error.  n must be
-       incremented to account for the initial value of -1 instead of
-       0.
-    */
-    n++;
 
  err:
     Py_DECREF(iter);
+    if (ind < 0)
+      return -1;
     return n;
 }
 

Modified: ZODB/branches/3.9/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/branches/3.9/src/BTrees/tests/testBTrees.py	2010-09-20 13:02:45 UTC (rev 116668)
+++ ZODB/branches/3.9/src/BTrees/tests/testBTrees.py	2010-09-20 17:08:13 UTC (rev 116669)
@@ -1387,10 +1387,13 @@
     def _noneraisesvalue(self):
         self.t[1] = None
 
-class TestIOSets(TestCase):
-    def setUp(self):
-        self.t = IOSet()
+class TestI_Sets(TestCase):
 
+    def testBadBadKeyAfterFirst(self):
+        self.assertRaises(TypeError, self.t.__class__, [1, ''])
+        self.assertRaises(TypeError, self.t.update, [1, ''])
+        del self.t
+
     def testNonIntegerInsertRaises(self):
         self.assertRaises(TypeError,self._insertstringraises)
         self.assertRaises(TypeError,self._insertfloatraises)
@@ -1405,6 +1408,47 @@
     def _insertnoneraises(self):
         self.t.insert(None)
 
+class TestIOSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = IOSet()
+
+class TestIOTreeSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = IOTreeSet()
+
+class TestIISets(TestI_Sets):
+
+    def setUp(self):
+        self.t = IISet()
+
+class TestIITreeSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = IITreeSet()
+
+class TestLOSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = LOSet()
+
+class TestLOTreeSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = LOTreeSet()
+
+class TestLLSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = LLSet()
+
+class TestLLTreeSets(TestI_Sets):
+
+    def setUp(self):
+        self.t = LLTreeSet()
+
+
 class DegenerateBTree(TestCase):
     # Build a degenerate tree (set).  Boxes are BTree nodes.  There are
     # 5 leaf buckets, each containing a single int.  Keys in the BTree
@@ -1758,7 +1802,6 @@
         self.assertEqual(len(t), 0)
         self.assertEqual(len(LP294788_ids), 0)
 
-
 class IIBTreeTest(BTreeTests):
     def setUp(self):
         self.t = IIBTree()
@@ -2083,7 +2126,8 @@
         # checking for assorted TypeErrors, and when both keys
         # and values are objects (OO), there's nothing to test.
         TestIIBTrees, TestIFBTrees,  TestIOBTrees,  TestOIBTrees,
-        TestIOSets,
+        TestIOSets, TestIOTreeSets, TestIISets, TestIITreeSets,
+        TestLOSets, TestLOTreeSets, TestLLSets, TestLLTreeSets,
         DegenerateBTree,
         TestCmpError,
         BugFixes,

Modified: ZODB/branches/3.9/src/CHANGES.txt
===================================================================
--- ZODB/branches/3.9/src/CHANGES.txt	2010-09-20 13:02:45 UTC (rev 116668)
+++ ZODB/branches/3.9/src/CHANGES.txt	2010-09-20 17:08:13 UTC (rev 116669)
@@ -17,6 +17,10 @@
 
   Fixes: https://bugs.launchpad.net/zodb/+bug/135108
 
+- BTree sets and tree sets didn't correctly check values passed to
+  update or to constructors, causing Python to exit under certain
+  circumstances.
+
 3.9.5 (2010-04-23)
 ==================
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.