[pypy-svn] pypy jit-tagged: For use of erasing by the JIT, we need at least one oopspec,

arigo commits-noreply at bitbucket.org
Mon Dec 20 13:20:47 CET 2010


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-tagged
Changeset: r40143:b02753f75fa8
Date: 2010-12-20 10:06 +0100
http://bitbucket.org/pypy/pypy/changeset/b02753f75fa8/

Log:	For use of erasing by the JIT, we need at least one oopspec,
	because is_integer(x) should not force x if it is a virtual.

diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -18,7 +18,8 @@
 def erase(x):
     """Creates an 'erased' object that contains a reference to 'x'. Nothing can
     be done with this object, except calling unerase(y, <type>) on it.
-    x needs to be either an instance or an integer fitting into 31/63 bits."""
+    x needs to be either an instance or an integer (in the latter case,
+    you get reliably an OverflowError if it doesn't fit into 31/63 bits)."""
     if isinstance(x, int):
         res = 2 * x + 1
         if res > sys.maxint or res < -sys.maxint - 1:
@@ -50,6 +51,7 @@
 def is_integer(e):
     """Gives information whether the erased argument is a tagged integer or not."""
     return isinstance(e._x, int)
+is_integer.oopspec = 'rerased.is_integer(e)'
 
 
 # ---------- implementation-specific ----------

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
@@ -118,13 +118,13 @@
         try:
             e = erase(i)
         except OverflowError:
-            return -1
+            return -42
         assert is_integer(e)
         return unerase(e, int)
     x = interpret(f, [16])
     assert x == 16
     x = interpret(f, [sys.maxint])
-    assert x == -1
+    assert x == -42
 
 def test_none():
     def foo():

diff --git a/pypy/rpython/lltypesystem/rtagged.py b/pypy/rpython/lltypesystem/rtagged.py
--- a/pypy/rpython/lltypesystem/rtagged.py
+++ b/pypy/rpython/lltypesystem/rtagged.py
@@ -141,6 +141,9 @@
         return hop.gendirectcall(ll_unboxed_isinstance_const, v_obj,
                                  minid, maxid, c_answer_if_unboxed)
 
+def ll_is_integer(instance):
+    return (lltype.cast_ptr_to_int(instance) & 1) != 0
+ll_is_integer.oopspec = 'rerased.is_integer(instance)'
 
 def ll_int_to_unboxed(PTRTYPE, value):
     return lltype.cast_int_to_ptr(PTRTYPE, value*2+1)
@@ -154,14 +157,14 @@
     return lltype.nullptr(lltype.typeOf(instance).TO.typeptr.TO)
 
 def ll_unboxed_getclass(instance, class_if_unboxed):
-    if lltype.cast_ptr_to_int(instance) & 1:
+    if ll_is_integer(instance):
         return class_if_unboxed
     return instance.typeptr
 
 def ll_unboxed_isinstance_const(obj, minid, maxid, answer_if_unboxed):
     if not obj:
         return False
-    if lltype.cast_ptr_to_int(obj) & 1:
+    if ll_is_integer(obj):
         return answer_if_unboxed
     else:
         return ll_issubclass_const(obj.typeptr, minid, maxid)


More information about the Pypy-commit mailing list