[pypy-svn] r69937 - in pypy/branch/virtual-forcing/pypy/rpython: . lltypesystem lltypesystem/test
arigo at codespeak.net
arigo at codespeak.net
Sun Dec 6 21:27:48 CET 2009
Author: arigo
Date: Sun Dec 6 21:27:45 2009
New Revision: 69937
Modified:
pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/branch/virtual-forcing/pypy/rpython/rtyper.py
Log:
Special treatment of vtables, in addition to special treatment
of objects.
Modified: pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/ll2ctypes.py Sun Dec 6 21:27:45 2009
@@ -21,7 +21,7 @@
from pypy.rlib.rarithmetic import r_uint, r_singlefloat, intmask
from pypy.annotation import model as annmodel
from pypy.rpython.llinterp import LLInterpreter, LLException
-from pypy.rpython.lltypesystem.rclass import OBJECT
+from pypy.rpython.lltypesystem.rclass import OBJECT, OBJECT_VTABLE
from pypy.rpython import raddress
from pypy.translator.platform import platform
@@ -690,6 +690,14 @@
if REAL_TYPE != T.TO:
p = container._as_ptr()
container = lltype.cast_pointer(T, p)._as_obj()
+ # special treatment of 'OBJECT_VTABLE' subclasses
+ if get_rtyper() and lltype._castdepth(REAL_TYPE,
+ OBJECT_VTABLE) >= 0:
+ # figure out the real object that this vtable points to,
+ # and just return that
+ p = get_rtyper().get_real_typeptr_for_typeptr(
+ container._as_ptr())
+ container = lltype.cast_pointer(T, p)._as_obj()
elif isinstance(T.TO, lltype.Array):
if T.TO._hints.get('nolength', False):
container = _array_of_unknown_length(T.TO)
Modified: pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/virtual-forcing/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Sun Dec 6 21:27:45 2009
@@ -1185,6 +1185,25 @@
res = interpret(f, [123])
assert res == 123
+ def test_object_subclass_5(self):
+ from pypy.rpython.lltypesystem import rclass
+ from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
+ from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
+ class S:
+ x = 5 # entry in the vtable
+ class T(S):
+ x = 6
+ def f():
+ s = T()
+ ls = cast_instance_to_base_ptr(s)
+ as_num = rffi.cast(lltype.Signed, ls)
+ # --- around this point, only 'as_num' is passed
+ t = rffi.cast(rclass.OBJECTPTR, as_num)
+ u = cast_base_ptr_to_instance(S, t)
+ return u.x
+ res = interpret(f, [])
+ assert res == 6
+
class TestPlatform(object):
def test_lib_on_libpaths(self):
from pypy.translator.platform import platform
Modified: pypy/branch/virtual-forcing/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/rpython/rtyper.py (original)
+++ pypy/branch/virtual-forcing/pypy/rpython/rtyper.py Sun Dec 6 21:27:45 2009
@@ -153,6 +153,14 @@
def set_type_for_typeptr(self, typeptr, TYPE):
self.type_for_typeptr[typeptr._obj] = TYPE
+ def get_real_typeptr_for_typeptr(self, typeptr):
+ # perform a linear scan for the case of ll2ctypes typeptr
+ search = typeptr._obj
+ for key, value in self.type_for_typeptr.items():
+ if key == search:
+ return key._as_ptr()
+ raise KeyError(search)
+
def makekey(self, s_obj):
return pair(self.type_system, s_obj).rtyper_makekey(self)
More information about the Pypy-commit
mailing list