[pypy-commit] pypy py3.5-siphash24: hg merge rpython-hash

arigo pypy.commits at gmail.com
Tue Jan 31 08:42:24 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5-siphash24
Changeset: r89854:2c4a4e1bf21e
Date: 2017-01-31 14:41 +0100
http://bitbucket.org/pypy/pypy/changeset/2c4a4e1bf21e/

Log:	hg merge rpython-hash

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]


More information about the pypy-commit mailing list