Author: Armin Rigo <ar...@tunes.org> Branch: rpython-hash Changeset: r89853:e5916c9c44b3 Date: 2017-01-31 14:40 +0100 http://bitbucket.org/pypy/pypy/changeset/e5916c9c44b3/
Log: Test and fix. I'll switch to recommend 'rr' now... 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 @@ -338,11 +338,15 @@ return DictIteratorRepr(self, "items").newiter(hop) def rtype_method_iterkeys_with_hash(self, hop): - hop.exception_cannot_occur() + v_dic, = hop.inputargs(self) + hop.exception_is_here() + hop.gendirectcall(ll_ensure_indexes, v_dic) return DictIteratorRepr(self, "keys_with_hash").newiter(hop) def rtype_method_iteritems_with_hash(self, hop): - hop.exception_cannot_occur() + v_dic, = hop.inputargs(self) + hop.exception_is_here() + hop.gendirectcall(ll_ensure_indexes, v_dic) return DictIteratorRepr(self, "items_with_hash").newiter(hop) def rtype_method_clear(self, hop): diff --git a/rpython/translator/c/test/test_typed.py b/rpython/translator/c/test/test_typed.py --- a/rpython/translator/c/test/test_typed.py +++ b/rpython/translator/c/test/test_typed.py @@ -644,6 +644,25 @@ def test_hash_string_siphash24(self): self._test_hash_string("siphash24") + def test_iterkeys_with_hash_on_prebuilt_dict(self): + from rpython.rlib import objectmodel + prebuilt_d = {"hello": 10, "world": 20} + # + def fn(n): + from rpython.rlib import rsiphash + rsiphash.enable_siphash24() + #assert str(n) not in prebuilt_d <- this made the test pass, + # before the fix which was that iterkeys_with_hash() + # didn't do the initial rehashing on its own + for key, h in objectmodel.iterkeys_with_hash(prebuilt_d): + print key, h + assert h == compute_hash(key) + return 42 + + f = self.getcompiled(fn, [int]) + res = f(0) + assert res == 42 + def test_list_basic_ops(self): def list_basic_ops(i, j): l = [1, 2, 3] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit