Author: Carl Friedrich Bolz <[email protected]>
Branch: 
Changeset: r48319:d33ecc0a1ac0
Date: 2011-10-21 17:58 +0200
http://bitbucket.org/pypy/pypy/changeset/d33ecc0a1ac0/

Log:    (arigo, cfbolz): add sanity checks to make sure that tagged pointers
        are enabled when erase_int is used.

diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -135,6 +135,8 @@
     _about_ = erase_int
 
     def compute_result_annotation(self, s_obj):
+        config = self.bookkeeper.annotator.translator.config
+        assert config.translation.taggedpointers, "need to enable tagged 
pointers to use erase_int"
         assert annmodel.SomeInteger().contains(s_obj)
         return SomeErased()
 
@@ -228,6 +230,8 @@
 
     def convert_const(self, value):
         if value._identity is _identity_for_ints:
+            config = self.rtyper.annotator.translator.config
+            assert config.translation.taggedpointers, "need to enable tagged 
pointers to use erase_int"
             return lltype.cast_int_to_ptr(self.lowleveltype, value._x * 2 + 1)
         bk = self.rtyper.annotator.bookkeeper
         s_obj = value._identity.get_input_annotation(bk)
diff --git a/pypy/rlib/test/test_rerased.py b/pypy/rlib/test/test_rerased.py
--- a/pypy/rlib/test/test_rerased.py
+++ b/pypy/rlib/test/test_rerased.py
@@ -10,6 +10,13 @@
 
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
+def make_annotator():
+    a = RPythonAnnotator()
+    a.translator.config.translation.taggedpointers = True
+    return a
+
+
+
 class X(object):
     pass
 
@@ -55,7 +62,7 @@
 def test_annotate_1():
     def f():
         return eraseX(X())
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [])
     assert isinstance(s, SomeErased)
 
@@ -66,7 +73,7 @@
         #assert not is_integer(e)
         x2 = uneraseX(e)
         return x2
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [])
     assert isinstance(s, annmodel.SomeInstance)
     assert s.classdef == a.bookkeeper.getuniqueclassdef(X)
@@ -77,7 +84,7 @@
         #assert is_integer(e)
         x2 = unerase_int(e)
         return x2
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [])
     assert isinstance(s, annmodel.SomeInteger)
 
@@ -105,7 +112,7 @@
         x = make(n)
         return check(x, n)
     #
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [int])
     assert isinstance(s, annmodel.SomeInteger)
 
@@ -135,7 +142,7 @@
             else:
                 return inst
     #
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [])
     assert isinstance(s, annmodel.SomeInstance)
     assert s.classdef == a.bookkeeper.getuniqueclassdef(A)
@@ -155,7 +162,7 @@
             e = e2
         return unerase(e)
     #
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [int])
     assert isinstance(s, annmodel.SomeInstance)
     assert s.classdef == a.bookkeeper.getuniqueclassdef(X)
@@ -165,11 +172,14 @@
     e1 = erase_int(42)
     def f(i):
         return unerase_int(e1)
-    a = RPythonAnnotator()
+    a = make_annotator()
     s = a.build_types(f, [int])
     assert isinstance(s, annmodel.SomeInteger)
 
 class BaseTestRErased(BaseRtypingTest):
+    def interpret(self, *args, **kwargs):
+        kwargs["taggedpointers"] = True
+        return BaseRtypingTest.interpret(self, *args, **kwargs)
     def test_rtype_1(self):
         def f():
             return eraseX(X())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to