Commit bccbdf8b authored by Jason Madden's avatar Jason Madden

Fix setting _p_changed when removing from small BTrees/TreeSets. The fix for #11 was incomplete.

parent fc5e6662
......@@ -942,6 +942,12 @@ class _Tree(_Base):
removed_first_bucket, value = child._del(key)
# See comment in _set about small trees
if (len(data) == 1 and
child.__class__ is self._bucket_type and
child._p_oid is None):
self._p_changed = True
# fix up the node key, but not for the 0'th one.
if index > 0 and child.size and key == data[index].key:
self._p_changed = True
......
......@@ -1146,6 +1146,37 @@ class BTreeTests(MappingBase):
self.assertTrue(t._p_changed)
self.assertEqual(t, t._p_jar.registered)
def testRemoveInSmallMapSetsChanged(self):
# A bug in the BTree Python implementation once caused
# deleting from a small btree to set _p_changed
t = self._makeOne()
# Note that for the property to actually hold, we have to fake a
# _p_jar and _p_oid
t._p_oid = b'\0\0\0\0\0'
class Jar(object):
def __init__(self):
self._cache = self
self.registered = None
def mru(self, arg):
pass
def readCurrent(self, arg):
pass
def register(self, arg):
self.registered = arg
t._p_jar = Jar()
t[0] = 1
# reset these, setting _firstbucket triggered a change
t._p_changed = False
t._p_jar.registered = None
# now remove the second value
del t[0]
self.assertTrue(t._p_changed)
self.assertEqual(t, t._p_jar.registered)
class NormalSetTests(Base):
# Test common to all set types
......@@ -1354,6 +1385,37 @@ class NormalSetTests(Base):
pass
self.assertEqual(x, keys)
def testRemoveInSmallSetSetsChanged(self):
# A bug in the BTree TreeSet Python implementation once caused
# deleting an item in a small set to fail to set _p_changed
t = self._makeOne()
# Note that for the property to actually hold, we have to fake a
# _p_jar and _p_oid
t._p_oid = b'\0\0\0\0\0'
class Jar(object):
def __init__(self):
self._cache = self
self.registered = None
def mru(self, arg):
pass
def readCurrent(self, arg):
pass
def register(self, arg):
self.registered = arg
t._p_jar = Jar()
t.add(0)
# reset these, setting _firstbucket triggered a change
t._p_changed = False
t._p_jar.registered = None
# now remove the second value
t.remove(0)
self.assertTrue(t._p_changed)
self.assertEqual(t, t._p_jar.registered)
class ExtendedSetTests(NormalSetTests):
def testLen(self):
......
......@@ -4,7 +4,9 @@
4.1.3 (unreleased)
------------------
- TBD
- Fix _p_changed when removing items from small pure-Python
BTrees/TreeSets. See:
https://github.com/zopefoundation/BTrees/issues/13
4.1.2 (2015-04-07)
......@@ -13,8 +15,9 @@
- Suppress testing 64-bit values in OLBTrees on 32 bit machines.
See: https://github.com/zopefoundation/BTrees/issues/9
- Fix _p_changed for small pure-Python BTrees.
See https://github.com/zopefoundation/BTrees/issues/11
- Fix _p_changed when adding items to small pure-Python
BTrees/TreeSets. See:
https://github.com/zopefoundation/BTrees/issues/11
4.1.1 (2014-12-27)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment