[pypy-commit] pypy numpy-back-to-applevel: fix dict.pop() in RPython with instances.
alex_gaynor
noreply at buildbot.pypy.org
Thu Jan 26 22:35:48 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51823:45f2ee87bb74
Date: 2012-01-26 16:34 -0500
http://bitbucket.org/pypy/pypy/changeset/45f2ee87bb74/
Log: fix dict.pop() in RPython with instances.
diff --git a/pypy/rpython/lltypesystem/rdict.py b/pypy/rpython/lltypesystem/rdict.py
--- a/pypy/rpython/lltypesystem/rdict.py
+++ b/pypy/rpython/lltypesystem/rdict.py
@@ -331,7 +331,8 @@
v_args = hop.inputargs(self, self.key_repr, self.value_repr)
target = ll_pop_default
hop.exception_is_here()
- return hop.gendirectcall(target, *v_args)
+ v_res = hop.gendirectcall(target, *v_args)
+ return self.recast_value(hop.llops, v_res)
class __extend__(pairtype(DictRepr, rmodel.Repr)):
diff --git a/pypy/rpython/test/test_rdict.py b/pypy/rpython/test/test_rdict.py
--- a/pypy/rpython/test/test_rdict.py
+++ b/pypy/rpython/test/test_rdict.py
@@ -25,37 +25,37 @@
class BaseTestRdict(BaseRtypingTest):
def test_dict_creation(self):
- def createdict(i):
+ def createdict(i):
d = {'hello' : i}
return d['hello']
res = self.interpret(createdict, [42])
assert res == 42
- def test_dict_getitem_setitem(self):
- def func(i):
+ def test_dict_getitem_setitem(self):
+ def func(i):
d = {'hello' : i}
d['world'] = i + 1
- return d['hello'] * d['world']
+ return d['hello'] * d['world']
res = self.interpret(func, [6])
assert res == 42
- def test_dict_getitem_keyerror(self):
- def func(i):
+ def test_dict_getitem_keyerror(self):
+ def func(i):
d = {'hello' : i}
try:
return d['world']
except KeyError:
- return 0
+ return 0
res = self.interpret(func, [6])
assert res == 0
def test_dict_del_simple(self):
- def func(i):
+ def func(i):
d = {'hello' : i}
d['world'] = i + 1
del d['hello']
- return len(d)
+ return len(d)
res = self.interpret(func, [6])
assert res == 1
@@ -71,7 +71,7 @@
assert res == True
def test_empty_strings(self):
- def func(i):
+ def func(i):
d = {'' : i}
del d['']
try:
@@ -83,7 +83,7 @@
res = self.interpret(func, [6])
assert res == 1
- def func(i):
+ def func(i):
d = {'' : i}
del d['']
d[''] = i + 1
@@ -146,8 +146,8 @@
d1 = {}
d1['hello'] = i + 1
d2 = {}
- d2['world'] = d1
- return d2['world']['hello']
+ d2['world'] = d1
+ return d2['world']['hello']
res = self.interpret(func, [5])
assert res == 6
@@ -297,7 +297,7 @@
a = 0
for k, v in items:
b += isinstance(k, B)
- a += isinstance(v, A)
+ a += isinstance(v, A)
return 3*b+a
res = self.interpret(func, [])
assert res == 8
@@ -316,7 +316,7 @@
a = 0
for k, v in dic.iteritems():
b += isinstance(k, B)
- a += isinstance(v, A)
+ a += isinstance(v, A)
return 3*b+a
res = self.interpret(func, [])
assert res == 8
@@ -342,11 +342,11 @@
def test_dict_contains_with_constant_dict(self):
dic = {'4':1000, ' 8':200}
def func(i):
- return chr(i) in dic
- res = self.interpret(func, [ord('4')])
+ return chr(i) in dic
+ res = self.interpret(func, [ord('4')])
assert res is True
- res = self.interpret(func, [1])
- assert res is False
+ res = self.interpret(func, [1])
+ assert res is False
def test_dict_or_none(self):
class A:
@@ -413,7 +413,7 @@
return g(get)
res = self.interpret(f, [])
- assert res == 2
+ assert res == 2
def test_specific_obscure_bug(self):
class A: pass
@@ -642,6 +642,22 @@
res = self.interpret(f, [2, 5])
assert res == 31
+ def test_dict_pop_instance(self):
+ class A(object):
+ pass
+ def f(n):
+ d = {}
+ d[2] = A()
+ x = d.pop(n, None)
+ if x is None:
+ return 12
+ else:
+ return 15
+ res = self.interpret(f, [2])
+ assert res == 15
+ res = self.interpret(f, [700])
+ assert res == 12
+
class TestLLtype(BaseTestRdict, LLRtypeMixin):
def test_dict_but_not_with_char_keys(self):
def func(i):
@@ -653,19 +669,19 @@
res = self.interpret(func, [6])
assert res == 0
- def test_deleted_entry_reusage_with_colliding_hashes(self):
- def lowlevelhash(value):
+ def test_deleted_entry_reusage_with_colliding_hashes(self):
+ def lowlevelhash(value):
p = rstr.mallocstr(len(value))
for i in range(len(value)):
p.chars[i] = value[i]
- return rstr.LLHelpers.ll_strhash(p)
+ return rstr.LLHelpers.ll_strhash(p)
- def func(c1, c2):
- c1 = chr(c1)
- c2 = chr(c2)
+ def func(c1, c2):
+ c1 = chr(c1)
+ c2 = chr(c2)
d = {}
d[c1] = 1
- d[c2] = 2
+ d[c2] = 2
del d[c1]
return d[c2]
@@ -673,7 +689,7 @@
base = rdict.DICT_INITSIZE
for y in range(0, 256):
y = chr(y)
- y_hash = lowlevelhash(y) % base
+ y_hash = lowlevelhash(y) % base
char_by_hash.setdefault(y_hash, []).append(y)
x, y = char_by_hash[0][:2] # find a collision
@@ -681,18 +697,18 @@
res = self.interpret(func, [ord(x), ord(y)])
assert res == 2
- def func2(c1, c2):
- c1 = chr(c1)
- c2 = chr(c2)
+ def func2(c1, c2):
+ c1 = chr(c1)
+ c2 = chr(c2)
d = {}
d[c1] = 1
- d[c2] = 2
+ d[c2] = 2
del d[c1]
d[c1] = 3
- return d
+ return d
res = self.interpret(func2, [ord(x), ord(y)])
- for i in range(len(res.entries)):
+ for i in range(len(res.entries)):
assert not (res.entries.everused(i) and not res.entries.valid(i))
def func3(c0, c1, c2, c3, c4, c5, c6, c7):
@@ -707,9 +723,9 @@
c7 = chr(c7) ; d[c7] = 1; del d[c7]
return d
- if rdict.DICT_INITSIZE != 8:
+ if rdict.DICT_INITSIZE != 8:
py.test.skip("make dict tests more indepdent from initsize")
- res = self.interpret(func3, [ord(char_by_hash[i][0])
+ res = self.interpret(func3, [ord(char_by_hash[i][0])
for i in range(rdict.DICT_INITSIZE)])
count_frees = 0
for i in range(len(res.entries)):
@@ -727,9 +743,9 @@
del d[chr(ord('a') + i)]
return d
res = self.interpret(func, [0])
- assert len(res.entries) > rdict.DICT_INITSIZE
+ assert len(res.entries) > rdict.DICT_INITSIZE
res = self.interpret(func, [1])
- assert len(res.entries) == rdict.DICT_INITSIZE
+ assert len(res.entries) == rdict.DICT_INITSIZE
def test_dict_valid_resize(self):
# see if we find our keys after resize
@@ -864,7 +880,7 @@
def test_prebuilt_list_of_addresses(self):
from pypy.rpython.lltypesystem import llmemory
-
+
TP = lltype.Struct('x', ('y', lltype.Signed))
a = lltype.malloc(TP, flavor='raw', immortal=True)
b = lltype.malloc(TP, flavor='raw', immortal=True)
@@ -878,7 +894,7 @@
d = {a_a: 3, a_b: 4, a_c: 5}
d[a0] = 8
-
+
def func(i):
if i == 0:
ptr = a
@@ -908,7 +924,7 @@
return a == b
def rhash(a):
return 3
-
+
def func(i):
d = r_dict(eq, rhash, force_non_null=True)
if not i:
More information about the pypy-commit
mailing list