[Checkins] SVN: BTrees/branches/pure_python/ Prevent infinite loops in set operations.

Tres Seaver cvs-admin at zope.org
Mon Oct 22 15:17:30 UTC 2012


Log message for revision 128130:
  Prevent infinite loops in set operations.
  
  Note that some tests are still failing in pure-Python mode.

Changed:
  _U  BTrees/branches/pure_python/
  U   BTrees/branches/pure_python/BTrees/___BTree.py

-=-
Modified: BTrees/branches/pure_python/BTrees/___BTree.py
===================================================================
--- BTrees/branches/pure_python/BTrees/___BTree.py	2012-10-22 15:17:22 UTC (rev 128129)
+++ BTrees/branches/pure_python/BTrees/___BTree.py	2012-10-22 15:17:26 UTC (rev 128130)
@@ -341,6 +341,7 @@
             set(*i)
 
     def __setitem__(self, key, value):
+        # TODO:  enforce test that key has non-default comparison?
         self._set(self._to_key(key), self._to_value(value))
 
     def __delitem__(self, key):
@@ -1011,8 +1012,8 @@
         if MERGE_DEFAULT is not None:
             i1.value = i2.value = MERGE_DEFAULT
         else:
-            if i1.usesValue:
-                if (not i2.usesValue) and c2:
+            if i1.useValues:
+                if (not i2.useValues) and c2:
                     raise TypeError("invalid set operation")
             else:
                 if c1 or c12:
@@ -1023,35 +1024,37 @@
         def copy(i, w):
             r._keys.append(i.key)
             r._values.append(MERGE_WEIGHT(i, w))
-            i.advance()
     else:
         r = s1._set_type()
         def copy(i, w):
             r._keys.append(i.key)
-            i.advance()
 
     while i1.active and i2.active:
         cmp_ = cmp(i1.key, i2.key)
         if cmp_ < 0:
             if c1:
                 copy(i1, w1)
+            i1.advance()
         elif cmp_ == 0:
             if c12:
                 r._keys.append(i1.key)
                 if merge:
                     r._values.append(MERGE(i1.value, w1, i2.value, w2))
-                i1.advance()
-                i2.advance()
+            i1.advance()
+            i2.advance()
         else:
             if c2:
                 copy(i2, w2)
+            i2.advance()
 
     if c1:
         while i1.active:
             copy(i1, w1)
+            i1.advance()
     if c2:
         while i2.active:
             copy(i2, w2)
+            i2.advance()
 
     return r
 



More information about the checkins mailing list