[pypy-commit] pypy rdict-experiments-3: (arigo) add some more paranoia
fijal
noreply at buildbot.pypy.org
Wed Oct 9 19:13:15 CEST 2013
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: rdict-experiments-3
Changeset: r67255:775d6e5f7190
Date: 2013-10-09 19:12 +0200
http://bitbucket.org/pypy/pypy/changeset/775d6e5f7190/
Log: (arigo) add some more paranoia
diff --git a/rpython/rtyper/lltypesystem/rdict.py b/rpython/rtyper/lltypesystem/rdict.py
--- a/rpython/rtyper/lltypesystem/rdict.py
+++ b/rpython/rtyper/lltypesystem/rdict.py
@@ -700,10 +700,20 @@
FLAG_LOOKUP = 0
FLAG_STORE = 1
FLAG_DELETE = 2
+FLAG_DELETE_TRY_HARD = 3
def new_lookup_functions(LOOKUP_FUNC, LOOKCLEAN_FUNC, T):
INDEXES = lltype.Ptr(lltype.GcArray(T))
+ def ll_kill_something(d):
+ i = 0
+ while True:
+ index = rffi.cast(lltype.Signed, d.indexes[i])
+ if index >= VALID_OFFSET:
+ d.indexes[i] = rffi.cast(T, DELETED)
+ return index
+ i += 1
+
@jit.look_inside_iff(lambda d, key, hash, store_flag:
jit.isvirtual(d) and jit.isconstant(key))
def ll_dict_lookup(d, key, hash, store_flag):
@@ -749,6 +759,8 @@
# pristine entry -- lookup failed
if store_flag == FLAG_STORE:
indexes[i] = rffi.cast(T, d.num_used_items + VALID_OFFSET)
+ elif d.paranoia and store_flag == FLAG_DELETE_TRY_HARD:
+ return ll_kill_something(d)
return -1
# In the loop, a deleted entry (everused and not valid) is by far
@@ -767,6 +779,8 @@
deletedslot = i
indexes[deletedslot] = rffi.cast(T, d.num_used_items +
VALID_OFFSET)
+ elif d.paranoia and store_flag == FLAG_DELETE_TRY_HARD:
+ return ll_kill_something(d)
return -1
elif index >= VALID_OFFSET:
checkingkey = entries[index].key
@@ -1071,7 +1085,15 @@
i -= 1
key = entries[i].key
- return dic.lookup_function(dic, key, dic.keyhash(key), FLAG_DELETE)
+ index = dic.lookup_function(dic, key, dic.keyhash(key),
+ FLAG_DELETE_TRY_HARD)
+ # if the lookup function returned me a random strange thing,
+ # don't care about deleting the item
+ if index == dic.num_used_items - 1:
+ dic.num_used_items -= 1
+ else:
+ assert index != -1
+ return index
def ll_popitem(ELEM, dic):
i = _ll_getnextitem(dic)
diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py
--- a/rpython/rtyper/test/test_rdict.py
+++ b/rpython/rtyper/test/test_rdict.py
@@ -170,7 +170,7 @@
rdict.ll_dict_setitem(ll_d, num, 1)
rdict.ll_dict_delitem(ll_d, num)
for k in foreach_index(ll_d):
- assert k < 0
+ assert k < rdict.VALID_OFFSET
class TestRdict(BaseRtypingTest):
More information about the pypy-commit
mailing list