[pypy-svn] r23579 - in pypy/dist/pypy: annotation jit rpython rpython/lltypesystem rpython/lltypesystem/test rpython/memory rpython/test translator/c/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Feb 21 23:44:32 CET 2006
Author: cfbolz
Date: Tue Feb 21 23:44:30 2006
New Revision: 23579
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/jit/rtimeshift.py
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/lltypesystem/llmemory.py
pypy/dist/pypy/rpython/lltypesystem/lltype.py
pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
pypy/dist/pypy/rpython/memory/gctransform.py
pypy/dist/pypy/rpython/memory/lladdress.py
pypy/dist/pypy/rpython/memory/lltypesimulation.py
pypy/dist/pypy/rpython/objectmodel.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/test/test_objectmodel.py
pypy/dist/pypy/translator/c/test/test_symbolic.py
Log:
(cfbolz, pedronis):
move cast_ptr_to_adr and cast_adr_to_ptr from objectmodel to llmemory
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue Feb 21 23:44:30 2006
@@ -315,10 +315,10 @@
def robjmodel_hint(s, **kwds_s):
return s
-def robjmodel_cast_ptr_to_adr(s):
+def llmemory_cast_ptr_to_adr(s):
return SomeAddress()
-def robjmodel_cast_adr_to_ptr(s, s_type):
+def llmemory_cast_adr_to_ptr(s, s_type):
assert s_type.is_constant()
return SomePtr(s_type.const)
@@ -367,8 +367,8 @@
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.hlinvoke] = robjmodel_hlinvoke
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.keepalive_until_here] = robjmodel_keepalive_until_here
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.hint] = robjmodel_hint
-BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_ptr_to_adr] = robjmodel_cast_ptr_to_adr
-BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_adr_to_ptr] = robjmodel_cast_adr_to_ptr
+BUILTIN_ANALYZERS[pypy.rpython.lltypesystem.llmemory.cast_ptr_to_adr] = llmemory_cast_ptr_to_adr
+BUILTIN_ANALYZERS[pypy.rpython.lltypesystem.llmemory.cast_adr_to_ptr] = llmemory_cast_adr_to_ptr
BUILTIN_ANALYZERS[pypy.rpython.rstack.yield_current_frame_to_caller] = (
rstack_yield_current_frame_to_caller)
Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py (original)
+++ pypy/dist/pypy/jit/rtimeshift.py Tue Feb 21 23:44:30 2006
@@ -1,5 +1,4 @@
-from pypy.rpython.lltypesystem import lltype, lloperation
-from pypy.rpython import objectmodel
+from pypy.rpython.lltypesystem import lltype, lloperation, llmemory
from pypy.rpython import rgenop
FOLDABLE_OPS = dict.fromkeys(lloperation.enum_foldable_ops())
@@ -49,7 +48,7 @@
def ll_fromvalue(value):
T = lltype.typeOf(value)
if isinstance(T, lltype.Ptr):
- return AddrRedBox(objectmodel.cast_ptr_to_adr(value))
+ return AddrRedBox(llmemory.cast_ptr_to_adr(value))
elif T is lltype.Float:
return DoubleRedBox(value)
else:
@@ -62,7 +61,7 @@
# note: this is specialized by low-level type T, as a low-level helper
if isinstance(T, lltype.Ptr):
assert isinstance(self, AddrRedBox)
- return objectmodel.cast_adr_to_ptr(self.adrvalue, T)
+ return llmemory.cast_adr_to_ptr(self.adrvalue, T)
elif T is lltype.Float:
assert isinstance(self, DoubleRedBox)
return self.dblvalue
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Tue Feb 21 23:44:30 2006
@@ -3,7 +3,6 @@
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.memory import lladdress
from pypy.rpython.ootypesystem import ootype
-from pypy.rpython import objectmodel
import sys
import math
@@ -451,11 +450,11 @@
def op_cast_ptr_to_adr(self, ptr):
assert checkptr(ptr)
- return objectmodel.cast_ptr_to_adr(ptr)
+ return llmemory.cast_ptr_to_adr(ptr)
def op_cast_adr_to_ptr(self, TYPE, adr):
assert lltype.typeOf(adr) == llmemory.Address
- return objectmodel.cast_adr_to_ptr(adr, TYPE)
+ return llmemory.cast_adr_to_ptr(adr, TYPE)
def op_cast_int_to_float(self, i):
assert type(i) is int
Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py Tue Feb 21 23:44:30 2006
@@ -137,6 +137,9 @@
else:
self.offset.set(self.ob, value)
+ def _cast_to_ptr(self, EXPECTED_TYPE):
+ return lltype.cast_pointer(self.get(), EXPECTED_TYPE)
+
# XXX the indexing in code like
# addr.signed[0] = v
# is just silly. remove it.
@@ -175,3 +178,13 @@
Address = lltype.Primitive("Address", fakeaddress(None))
fakeaddress._TYPE = Address
+
+# the obtained address will not keep the object alive. e.g. if the object is
+# only reachable through an address, it might get collected
+def cast_ptr_to_adr(obj):
+ assert isinstance(lltype.typeOf(obj), lltype.Ptr)
+ return obj._cast_to_adr()
+
+def cast_adr_to_ptr(adr, EXPECTED_TYPE):
+ return adr._cast_to_ptr(EXPECTED_TYPE)
+
Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Tue Feb 21 23:44:30 2006
@@ -797,6 +797,9 @@
obj = obj._parentstructure()
return id(obj)
+ def _cast_to_adr(self):
+ from pypy.rpython.lltypesystem import llmemory
+ return llmemory.fakeaddress(self)
assert not '__dict__' in dir(_ptr)
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py Tue Feb 21 23:44:30 2006
@@ -51,4 +51,32 @@
py.test.raises(AssertionError, "sizeof(varstruct)")
sizeof(array, 1)
sizeof(varstruct, 2)
-
+
+def test_cast_ptr_to_adr():
+ from pypy.rpython.memory.test.test_llinterpsim import interpret
+ class A(object):
+ pass
+ def f(x):
+ if x:
+ a = A()
+ else:
+ a = None
+ adr_a = cast_ptr_to_adr(a)
+ return bool(adr_a)
+ res = interpret(f, [1])
+ assert res
+ res = interpret(f, [0])
+ assert not res
+
+def test_cast_adr_to_ptr():
+ from pypy.rpython.memory.test.test_llinterpsim import interpret
+ from pypy.rpython.lltypesystem import lltype
+ S = lltype.GcStruct("S", ("x", lltype.Signed))
+ Sptr = lltype.Ptr(S)
+ def f():
+ s1 = lltype.malloc(S)
+ adr = cast_ptr_to_adr(s1)
+ s2 = cast_adr_to_ptr(adr, Sptr)
+ return s1 == s2
+ res = interpret(f, [])
+ assert res
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Tue Feb 21 23:44:30 2006
@@ -6,7 +6,7 @@
from pypy.translator.unsimplify import insert_empty_block
from pypy.translator.translator import graphof
from pypy.annotation import model as annmodel
-from pypy.rpython import rmodel, objectmodel, rptr, annlowlevel
+from pypy.rpython import rmodel, rptr, annlowlevel
from pypy.rpython.memory import gc, lladdress
import sets, os
@@ -431,7 +431,7 @@
'lltype': lltype,
'destrptr': destrptr,
'gc_header_offset': RefcountingGCTransformer.gc_header_offset,
- 'cast_adr_to_ptr': objectmodel.cast_adr_to_ptr,
+ 'cast_adr_to_ptr': llmemory.cast_adr_to_ptr,
'cast_pointer': lltype.cast_pointer,
'PTR_TYPE': lltype.Ptr(TYPE),
'DESTR_ARG': DESTR_ARG,
@@ -473,7 +473,7 @@
# bump refcount to 1
gcheader = addr - RefcountingGCTransformer.gc_header_offset
gcheader.signed[0] = 1
- v = objectmodel.cast_adr_to_ptr(addr, QUERY_ARG_TYPE)
+ v = llmemory.cast_adr_to_ptr(addr, QUERY_ARG_TYPE)
rtti = queryptr(v)
gcheader.signed[0] = 0
llop.gc_call_rtti_destructor(lltype.Void, rtti, addr)
@@ -575,7 +575,7 @@
static_body = '\n'.join(_static_deallocator_body_for_type('v', TYPE))
d = {'pop_alive':pop_alive,
'PTR_TYPE':lltype.Ptr(TYPE),
- 'cast_adr_to_ptr':objectmodel.cast_adr_to_ptr}
+ 'cast_adr_to_ptr': llmemory.cast_adr_to_ptr}
src = ("def finalizer(addr):\n"
" v = cast_adr_to_ptr(addr, PTR_TYPE)\n"
"%s\n")%(static_body,)
@@ -586,7 +586,7 @@
def finalizer(addr):
exc_instance = llop.gc_fetch_exception(EXC_INSTANCE_TYPE)
try:
- v = objectmodel.cast_adr_to_ptr(addr, DESTR_ARG)
+ v = llmemory.cast_adr_to_ptr(addr, DESTR_ARG)
destrptr(v)
except:
try:
Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py (original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py Tue Feb 21 23:44:30 2006
@@ -58,6 +58,10 @@
def __nonzero__(self):
return self.intaddress != 0
+
+ def _cast_to_ptr(self, EXPECTED_TYPE):
+ from pypy.rpython.memory.lltypesimulation import simulatorptr
+ return simulatorptr(EXPECTED_TYPE, self)
class _accessor(object):
Modified: pypy/dist/pypy/rpython/memory/lltypesimulation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lltypesimulation.py (original)
+++ pypy/dist/pypy/rpython/memory/lltypesimulation.py Tue Feb 21 23:44:30 2006
@@ -186,6 +186,9 @@
def _cast_to_int(self):
return self._address.intaddress
+ def _cast_to_adr(self):
+ return self._address
+
# for now use the simulators raw_malloc
def malloc(T, n=None, immortal=False, flavor='gc'):
fixedsize = get_fixed_size(T)
Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py (original)
+++ pypy/dist/pypy/rpython/objectmodel.py Tue Feb 21 23:44:30 2006
@@ -44,18 +44,6 @@
obj.__dict__ = {}
obj.__class__ = FREED_OBJECT
-# XXX these things don't clearly belong here XXX
-
-# the obtained address will not keep the object alive. e.g. if the object is
-# only reachable through an address, it might get collected
-def cast_ptr_to_adr(obj):
- from pypy.rpython.memory.lltypesimulation import simulatorptr
- assert isinstance(obj, simulatorptr)
- return obj._address
-
-def cast_adr_to_ptr(adr, EXPECTED_TYPE):
- from pypy.rpython.memory.lltypesimulation import simulatorptr
- return simulatorptr(EXPECTED_TYPE, adr)
# __ hlinvoke XXX this doesn't seem completely the right place for this
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Tue Feb 21 23:44:30 2006
@@ -1,7 +1,7 @@
from pypy.annotation.pairtype import pairtype
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Constant
-from pypy.rpython.lltypesystem import lltype, rclass
+from pypy.rpython.lltypesystem import lltype, rclass, llmemory
from pypy.rpython import rarithmetic, objectmodel, rstack, rint, raddress
from pypy.rpython.error import TyperError
from pypy.rpython.rmodel import Repr, IntegerRepr
@@ -475,6 +475,6 @@
return hop.genop('cast_adr_to_ptr', [adr],
resulttype = TYPE.value)
-BUILTIN_TYPER[objectmodel.cast_ptr_to_adr] = rtype_cast_ptr_to_adr
-BUILTIN_TYPER[objectmodel.cast_adr_to_ptr] = rtype_cast_adr_to_ptr
+BUILTIN_TYPER[llmemory.cast_ptr_to_adr] = rtype_cast_ptr_to_adr
+BUILTIN_TYPER[llmemory.cast_adr_to_ptr] = rtype_cast_adr_to_ptr
Modified: pypy/dist/pypy/rpython/test/test_objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_objectmodel.py (original)
+++ pypy/dist/pypy/rpython/test/test_objectmodel.py Tue Feb 21 23:44:30 2006
@@ -166,33 +166,4 @@
res = interpret(f, [])
assert res == 5
-def test_cast_ptr_to_adr():
- from pypy.rpython import objectmodel
- from pypy.rpython.memory.test.test_llinterpsim import interpret
- class A(object):
- pass
- def f(x):
- if x:
- a = A()
- else:
- a = None
- adr_a = objectmodel.cast_ptr_to_adr(a)
- return bool(adr_a)
- res = interpret(f, [1])
- assert res
- res = interpret(f, [0])
- assert not res
-def test_cast_adr_to_ptr():
- from pypy.rpython import objectmodel
- from pypy.rpython.memory.test.test_llinterpsim import interpret
- from pypy.rpython.lltypesystem import lltype
- S = lltype.GcStruct("S", ("x", lltype.Signed))
- Sptr = lltype.Ptr(S)
- def f():
- s1 = lltype.malloc(S)
- adr = objectmodel.cast_ptr_to_adr(s1)
- s2 = objectmodel.cast_adr_to_ptr(adr, Sptr)
- return s1 == s2
- res = interpret(f, [])
- assert res
Modified: pypy/dist/pypy/translator/c/test/test_symbolic.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_symbolic.py (original)
+++ pypy/dist/pypy/translator/c/test/test_symbolic.py Tue Feb 21 23:44:30 2006
@@ -2,7 +2,6 @@
from pypy import conftest
from pypy.rpython.lltypesystem import llmemory, lltype
from pypy.rpython.memory import lladdress
-from pypy.rpython import objectmodel
def getcompiled(f, args):
t = Translation(f)
@@ -18,7 +17,7 @@
def f():
s = lltype.malloc(STRUCT)
s.x = 1
- adr = objectmodel.cast_ptr_to_adr(s)
+ adr = llmemory.cast_ptr_to_adr(s)
result = (adr + offsetx).signed[0]
(adr + offsety).signed[0] = 2
return result * 10 + s.y
@@ -31,7 +30,7 @@
itemoffsets = [llmemory.itemoffsetof(ARRAY, i) for i in range(5)]
def f():
a = lltype.malloc(ARRAY, 5)
- adr = objectmodel.cast_ptr_to_adr(a)
+ adr = llmemory.cast_ptr_to_adr(a)
result = 0
for i in range(5):
a[i] = i + 1
@@ -54,7 +53,7 @@
offsety = llmemory.offsetof(STRUCT, 'y')
def f():
adr = lladdress.raw_malloc(sizeofs)
- s = objectmodel.cast_adr_to_ptr(adr, STRUCTPTR)
+ s = llmemory.cast_adr_to_ptr(adr, STRUCTPTR)
s.y = 5 # does not crash
result = (adr + offsety).signed[0] * 10 + int(offsety < sizeofs)
lladdress.raw_free(adr)
More information about the Pypy-commit
mailing list