Commit 84ace7a5 authored by Tim Peters's avatar Tim Peters

_BTree_set(): Fixes for "Guido's bug", and all the other kinds of BTree

deletion endcases uncovered by the new degenerate-BTree tests.  The
degenerate testDeletes() and testEmptyFirstBucketReportedByGuido() are
enabled now.
parent cf820929
This diff is collapsed.
......@@ -173,8 +173,11 @@ More or less random bits of helpful info.
more efficiently than they can store arbitrary Python objects.
+ In a non-empty BTree, every bucket node contains at least one key,
and every BTree node contains at least one child. An empty BTree
consists solely of a BTree node with len==0 and firstbucket==NULL.
and every BTree node contains at least one child and a non-NULL
firstbucket pointer. However, a BTree node may not contain any keys.
+ An empty BTree consists solely of a BTree node with len==0 and
firstbucket==NULL.
+ Although a BTree can become unbalanced under a mix of inserts and
deletes (meaning both that there's nothing stronger that can be
......
......@@ -759,7 +759,7 @@ class TestIOBTrees(BTreeTests, TestCase):
def _noneraises(self):
self.t[None] = 1
def XXXtestEmptyFirstBucketReportedByGuido(self):
def testEmptyFirstBucketReportedByGuido(self):
b = self.t
for i in xrange(29972): # reduce to 29971 and it works
b[i] = i
......@@ -994,20 +994,18 @@ class TestIITreeSets(NormalSetTests, TestCase):
t, keys = self._build_degenerate_tree()
self._checkRanges(t, keys)
def XXXtestDeletes(self):
def testDeletes(self):
# Delete keys in all possible orders, checking each tree along
# the way.
# XXX This is hopeless for now: it dies with:
# XXX 1. A variety of assertion failures in _checkRanges.
# XXX 2. Assorted "Invalid firstbucket pointer" failures at
# XXX seemingly random times, coming out of the BTree destructor.
# XXX 3. Under Python 2.3 CVS, some baffling
# XXX RuntimeWarning: tp_compare didn't return -1 or -2 for exception
# XXX warnings, possibly due to memory corruption after a BTree
# XXX goes insane.
# XXX These are probably related to "Guido's bug" (which test case
# SXX is also disabled for now).
# This is a tough test. Previous failure modes included:
# 1. A variety of assertion failures in _checkRanges.
# 2. Assorted "Invalid firstbucket pointer" failures at
# seemingly random times, coming out of the BTree destructor.
# 3. Under Python 2.3 CVS, some baffling
# RuntimeWarning: tp_compare didn't return -1 or -2 for exception
# warnings, possibly due to memory corruption after a BTree
# goes insane.
t, keys = self._build_degenerate_tree()
for oneperm in permutations(keys):
......@@ -1016,6 +1014,9 @@ class TestIITreeSets(NormalSetTests, TestCase):
t.remove(key)
keys.remove(key)
self._checkRanges(t, keys)
# We removed all the keys, so the tree should be empty now.
self.assertEqual(t.__getstate__(), None)
# A damaged tree may trigger an "invalid firstbucket pointer"
# failure at the time its destructor is invoked. Try to force
# that to happen now, so it doesn't look like a baffling failure
......
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