Author: Armin Rigo <[email protected]>
Branch: stmgc-static-barrier
Changeset: r66124:9dad0a4b286c
Date: 2013-08-13 16:46 +0200
http://bitbucket.org/pypy/pypy/changeset/9dad0a4b286c/

Log:    Use stm_pointer_equal_prebuilt; test.

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
@@ -69,11 +69,20 @@
         funcname, arg)
 
 def stm_ptr_eq(funcgen, op):
-    arg0 = funcgen.expr(op.args[0])
-    arg1 = funcgen.expr(op.args[1])
+    args = [funcgen.expr(v) for v in op.args]
     result = funcgen.expr(op.result)
+    # check for prebuilt arguments
+    for i, j in [(0, 1), (1, 0)]:
+        if isinstance(op.args[j], Constant):
+            if op.args[j].value:     # non-NULL
+                return ('%s = stm_pointer_equal_prebuilt((gcptr)%s, 
(gcptr)%s);'
+                        % (result, args[i], args[j]))
+            else:
+                # this case might be unreachable, but better safe than sorry
+                return '%s = (%s == NULL);' % (result, args[i])
+    #
     return '%s = stm_pointer_equal((gcptr)%s, (gcptr)%s);' % (
-        result, arg0, arg1)
+        result, args[0], args[1])
 
 def stm_become_inevitable(funcgen, op):
     try:
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
@@ -301,3 +301,31 @@
         t, cbuilder = self.compile(main)
         data = cbuilder.cmdexec('a b')
         assert 'test ok\n' in data
+
+    def test_stm_pointer_equal(self):
+        class Foo:
+            pass
+        prebuilt_foo = Foo()
+        def make(n):
+            foo1 = Foo()
+            foo2 = Foo()
+            if n < 100:
+                return foo1, foo2, foo1, None
+            return None, None, None, foo1     # to annotate as "can be none"
+        def main(argv):
+            foo1, foo2, foo3, foo4 = make(len(argv))
+            assert foo1 is not prebuilt_foo
+            assert foo1 is not foo2
+            assert foo1 is foo3
+            assert foo4 is None
+            assert foo1 is not None
+            assert prebuilt_foo is not foo1
+            assert None is not foo1
+            assert None is foo4
+            print 'test ok'
+            return 0
+
+        main([])
+        t, cbuilder = self.compile(main)
+        data = cbuilder.cmdexec('')
+        assert 'test ok\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to