[pypy-svn] r37682 - in pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem: . test
ac at codespeak.net
ac at codespeak.net
Wed Jan 31 18:50:07 CET 2007
Author: ac
Date: Wed Jan 31 18:50:06 2007
New Revision: 37682
Modified:
pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/rvirtualizable.py
pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/test/test_rvirtualizable.py
Log:
(pedronis, arre) Fix for Void and non-redirected fields.
Modified: pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/rvirtualizable.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/rvirtualizable.py (original)
+++ pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/rvirtualizable.py Wed Jan 31 18:50:06 2007
@@ -45,13 +45,17 @@
redirected_fields = list(rbase.ACCESS.redirected_fields)
name = self.lowleveltype.TO._name
TOPPTR = self.get_top_virtualizable_type()
+ self.my_redirected_fields = my_redirected_fields = {}
for name, (mangled_name, r) in self.fields.items():
T = r.lowleveltype
+ if T is lltype.Void:
+ continue
GETTER = lltype.Ptr(lltype.FuncType([TOPPTR], T))
SETTER = lltype.Ptr(lltype.FuncType([TOPPTR, T], lltype.Void))
accessors.append(('get_'+mangled_name, GETTER))
accessors.append(('set_'+mangled_name, SETTER))
redirected_fields.append(mangled_name)
+ my_redirected_fields[name] = None
ACCESS.become(lltype.Struct(name+'_access',
hints = {'immutable': True},
adtmeths = {'redirected_fields': tuple(redirected_fields)},
@@ -124,7 +128,7 @@
def getfield(self, vinst, attr, llops, force_cast=False):
"""Read the given attribute (or __class__ for the type) of 'vinst'."""
- if attr in self.fields:
+ if attr in self.my_redirected_fields:
mangled_name, r = self.fields[attr]
if force_cast:
vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
@@ -135,7 +139,7 @@
def setfield(self, vinst, attr, vvalue, llops, force_cast=False, opname='setfield'):
"""Write the given attribute (or __class__ for the type) of 'vinst'."""
- if attr in self.fields:
+ if attr in self.my_redirected_fields:
mangled_name, r = self.fields[attr]
if force_cast:
vinst = llops.genop('cast_pointer', [vinst], resulttype=self)
Modified: pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/test/test_rvirtualizable.py
==============================================================================
--- pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/test/test_rvirtualizable.py (original)
+++ pypy/branch/jit-virtual-world/pypy/rpython/lltypesystem/test/test_rvirtualizable.py Wed Jan 31 18:50:06 2007
@@ -167,3 +167,36 @@
AA(3)
py.test.raises(TyperError, interpret, f, [])
+
+def test_read_not_redirected_field():
+ class V(object):
+ _virtualizable_ = True
+
+ def __init__(self, v):
+ self.v = v
+ def f(v):
+ vinst = V(v)
+ return vinst, vinst.v, vinst.__class__
+ res = interpret(f, [42])
+ assert res.item1 == 42
+
+
+def test_void_fields():
+ class F(object):
+ def _freeze_(self):
+ return True
+
+ f = F()
+
+ class V(object):
+ _virtualizable_ = True
+
+ def __init__(self, v):
+ self.v = v
+ self.f = f
+ def f(v):
+ vinst = V(v)
+ return vinst, vinst.v, vinst.f
+ res = interpret(f, [42])
+ assert res.item1 == 42
+
More information about the Pypy-commit
mailing list