Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r85121:4e4fa6046959
Date: 2016-06-13 11:53 +0200
http://bitbucket.org/pypy/pypy/changeset/4e4fa6046959/

Log:    Add a test checking the conversion_table() function and the
        pointer_table array. Add 'immutable' hints on these arrays.

diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -414,7 +414,7 @@
         if self.s_pbc.can_be_None:
             self.descriptions.insert(0, None)
         POINTER_TABLE = Array(self.pointer_repr.lowleveltype,
-                              hints={'nolength': True})
+                              hints={'nolength': True, 'immutable': True})
         pointer_table = malloc(POINTER_TABLE, len(self.descriptions),
                                immortal=True)
         for i, desc in enumerate(self.descriptions):
@@ -564,7 +564,7 @@
     if r_to in r_from._conversion_tables:
         return r_from._conversion_tables[r_to]
     else:
-        t = malloc(Array(Char, hints={'nolength': True}),
+        t = malloc(Array(Char, hints={'nolength': True, 'immutable': True}),
                    len(r_from.descriptions), immortal=True)
         l = []
         for i, d in enumerate(r_from.descriptions):
@@ -577,7 +577,7 @@
         if l == range(len(r_from.descriptions)):
             r = None
         else:
-            r = inputconst(Ptr(Array(Char, hints={'nolength': True})), t)
+            r = inputconst(typeOf(t), t)
         r_from._conversion_tables[r_to] = r
         return r
 
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -2012,6 +2012,36 @@
         e = py.test.raises(ValueError, self.interpret, f, [3])
         assert str(e.value).startswith(r"exit case '\xff' not found")
 
+    @py.test.mark.parametrize('limit', [3, 5])
+    def test_conversion_table(self, limit):
+        # with limit==3, check conversion from Char to Ptr(Func).
+        # with limit>3, check conversion from Char to Char.
+        def f1():
+            return 111
+        def f2():
+            return 222
+        def f3():
+            return 333
+        def g(n):
+            if n & 1:
+                return f1
+            else:
+                return f2
+        def f(n):
+            x = g(n)    # can be f1 or f2
+            if n > 10:
+                x = f3  # now can be f1 or f2 or f3
+            return x()
+
+        from rpython.config.translationoption import 
get_combined_translation_config
+        self.config = get_combined_translation_config(translating=True)
+        self.config.translation.withsmallfuncsets = limit
+        assert self.interpret(f, [3]) == 111
+        assert self.interpret(f, [4]) == 222
+        assert self.interpret(f, [13]) == 333
+        assert self.interpret(f, [14]) == 333
+
+
 def test_smallfuncsets_basic():
     from rpython.translator.translator import TranslationContext, graphof
     from rpython.config.translationoption import 
get_combined_translation_config
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to