[pypy-commit] pypy default: Minimal change to fix test_memoryerror_should_not_insert.
arigo
noreply at buildbot.pypy.org
Tue Dec 16 01:21:21 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r74951:bad1c782ed83
Date: 2014-12-16 00:14 +0000
http://bitbucket.org/pypy/pypy/changeset/bad1c782ed83/
Log: Minimal change to fix test_memoryerror_should_not_insert.
diff --git a/rpython/rtyper/lltypesystem/rordereddict.py b/rpython/rtyper/lltypesystem/rordereddict.py
--- a/rpython/rtyper/lltypesystem/rordereddict.py
+++ b/rpython/rtyper/lltypesystem/rordereddict.py
@@ -532,9 +532,27 @@
entry = d.entries[i]
entry.value = value
else:
+ reindexed = False
if len(d.entries) == d.num_ever_used_items:
- if ll_dict_grow(d):
- ll_call_insert_clean_function(d, hash, d.num_ever_used_items)
+ try:
+ reindexed = ll_dict_grow(d)
+ except MemoryError:
+ _ll_dict_rescue(d)
+ raise
+ rc = d.resize_counter - 3
+ if rc <= 0:
+ try:
+ ll_dict_resize(d)
+ reindexed = True
+ except MemoryError:
+ _ll_dict_rescue(d)
+ raise
+ rc = d.resize_counter - 3
+ ll_assert(rc > 0, "ll_dict_resize failed?")
+ if reindexed:
+ ll_call_insert_clean_function(d, hash, d.num_ever_used_items)
+ #
+ d.resize_counter = rc
entry = d.entries[d.num_ever_used_items]
entry.key = key
entry.value = value
@@ -544,12 +562,13 @@
entry.f_valid = True
d.num_ever_used_items += 1
d.num_live_items += 1
- rc = d.resize_counter - 3
- if rc <= 0:
- ll_dict_resize(d)
- rc = d.resize_counter - 3
- ll_assert(rc > 0, "ll_dict_resize failed?")
- d.resize_counter = rc
+
+def _ll_dict_rescue(d):
+ # MemoryError situation! The 'indexes' contains an invalid entry
+ # at this point. But we can call ll_dict_reindex() with the
+ # following arguments, ensuring no further malloc occurs.
+ ll_dict_reindex(d, _ll_len_of_d_indexes(d))
+_ll_dict_rescue._dont_inline_ = True
def _ll_dict_insertclean(d, key, value, hash):
ENTRY = lltype.typeOf(d.entries).TO.OF
diff --git a/rpython/rtyper/test/test_rordereddict.py b/rpython/rtyper/test/test_rordereddict.py
--- a/rpython/rtyper/test/test_rordereddict.py
+++ b/rpython/rtyper/test/test_rordereddict.py
@@ -292,9 +292,6 @@
res = self.interpret(func, [5])
assert res == 6
- def test_memoryerror_should_not_insert(self):
- py.test.skip("I don't want to edit this file on two branches")
-
class TestStress:
More information about the pypy-commit
mailing list