[pypy-svn] pypy 32ptr-on-64bit: Test and fix: if g is a low-level function pointer, then g(*args)

arigo commits-noreply at bitbucket.org
Sat Apr 16 22:11:57 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 32ptr-on-64bit
Changeset: r43406:2de9ed30dbdb
Date: 2011-04-16 13:07 -0700
http://bitbucket.org/pypy/pypy/changeset/2de9ed30dbdb/

Log:	Test and fix: if g is a low-level function pointer, then g(*args)
	might mess up the exact type of the args if the tuple stores them
	differently. This is a bit non-obvious to test, and is only
	apparent in HiddenGcRef32.

diff --git a/pypy/rpython/rbuiltin.py b/pypy/rpython/rbuiltin.py
--- a/pypy/rpython/rbuiltin.py
+++ b/pypy/rpython/rbuiltin.py
@@ -71,11 +71,11 @@
         if not isinstance(r_tuple, AbstractTupleRepr):
             raise TyperError("*arg must be a tuple")
         for i in range(len(r_tuple.items_r)):
-            v_item = r_tuple.getitem_internal(hop.llops, v_tuple, i)
+            v_item = r_tuple.getitem(hop.llops, v_tuple, i)
             hop.nb_args += 1
             hop.args_v.append(v_item)
             hop.args_s.append(s_tuple.items[i])
-            hop.args_r.append(r_tuple.items_r[i])
+            hop.args_r.append(r_tuple.external_items_r[i])
 
     keywords = arguments.keywords
     if not takes_kwds and keywords:

diff --git a/pypy/rpython/test/test_rcompressed.py b/pypy/rpython/test/test_rcompressed.py
--- a/pypy/rpython/test/test_rcompressed.py
+++ b/pypy/rpython/test/test_rcompressed.py
@@ -2,7 +2,8 @@
 from pypy.config.translationoption import IS_64_BITS
 from pypy.rpython.test import test_rclass
 from pypy.rpython import rmodel, rint, rclass
-from pypy.rpython.lltypesystem import llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem.lloperation import llop
 
 
 def setup_module(mod):
@@ -231,3 +232,27 @@
             return str([A()])
         res = self.interpret(fn, [])
         assert 'HiddenGcRef32' in self.ll_to_string(res)
+
+    def test_nonzero(self):
+        S = lltype.GcStruct('S')
+        def fn():
+            p = lltype.malloc(S)
+            r = llop.hide_into_ptr32(llmemory.HiddenGcRef32, p)
+            return bool(r)
+        res = self.interpret(fn, [])
+        assert res == True
+
+    def test_funccall_starargs(self):
+        def g(a, b):
+            return a.n - b.n
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+        SPTR = lltype.Ptr(S)
+        GFUNC = lltype.FuncType([SPTR, SPTR], lltype.Signed)
+        gptr = lltype.functionptr(GFUNC, 'g', _callable=g)
+        def fn(x, y):
+            a = lltype.malloc(S); a.n = x
+            b = lltype.malloc(S); b.n = y
+            args = (a, b)
+            return gptr(*args)
+        res = self.interpret(fn, [45, 3])
+        assert res == 42


More information about the Pypy-commit mailing list