[pypy-commit] pypy stmgc-c4: hash, id

arigo noreply at buildbot.pypy.org
Sun Jun 30 11:47:32 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c4
Changeset: r65122:74d273f9c9cd
Date: 2013-06-30 11:46 +0200
http://bitbucket.org/pypy/pypy/changeset/74d273f9c9cd/

Log:	hash, id

diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -592,6 +592,8 @@
     OP_STM_POP_ROOT_INTO = _OP_STM
     OP_STM_ALLOCATE = _OP_STM
     OP_STM_GET_TID = _OP_STM
+    OP_STM_HASH = _OP_STM
+    OP_STM_ID = _OP_STM
 
 
     def OP_PTR_NONZERO(self, op):
diff --git a/rpython/translator/stm/funcgen.py b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -97,6 +97,16 @@
     result = funcgen.expr(op.result)
     return '%s = stm_get_tid((gcptr)%s);' % (result, arg0)
 
+def stm_hash(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    result = funcgen.expr(op.result)
+    return '%s = stm_hash((gcptr)%s);' % (result, arg0)
+
+def stm_id(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    result = funcgen.expr(op.result)
+    return '%s = stm_id((gcptr)%s);' % (result, arg0)
+
 
 def op_stm(funcgen, op):
     func = globals()[op.opname]
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -27,6 +27,33 @@
         data = cbuilder.cmdexec('260')
         assert '< 260 >' in data, "got: %r" % (data,)
 
+    def test_hash_id(self):
+        from rpython.rlib.objectmodel import compute_identity_hash
+        from rpython.rlib.objectmodel import compute_unique_id
+        FOO = lltype.GcStruct('FOO')
+        prebuilt = lltype.malloc(FOO)
+        prebuilt_hash = lltype.identityhash(prebuilt)
+        #
+        def w(num, x):
+            print '%d>>>' % num, compute_identity_hash(x), compute_unique_id(x)
+        #
+        def entry_point(argv):
+            w(1, prebuilt)
+            w(2, lltype.malloc(FOO))
+            return 0
+        #
+        t, cbuilder = self.compile(entry_point, backendopt=True)
+        assert prebuilt_hash == lltype.identityhash(prebuilt)
+        data = cbuilder.cmdexec('')
+        data = data.split()
+        i1 = data.index('1>>>')
+        i2 = data.index('2>>>')
+        int(data[i1 + 1])
+        int(data[i1 + 2])
+        int(data[i2 + 1])
+        int(data[i2 + 2])
+        assert int(data[i1 + 1]) == prebuilt_hash
+
     def test_targetdemo(self):
         t, cbuilder = self.compile(targetdemo2.entry_point)
         data, dataerr = cbuilder.cmdexec('4 5000', err=True,


More information about the pypy-commit mailing list