[pypy-svn] r32393 - pypy/branch/kill-keepalives/pypy/rpython/rctypes
arigo at codespeak.net
arigo at codespeak.net
Sat Sep 16 19:08:56 CEST 2006
Author: arigo
Date: Sat Sep 16 19:08:54 2006
New Revision: 32393
Modified:
pypy/branch/kill-keepalives/pypy/rpython/rctypes/rarray.py
pypy/branch/kill-keepalives/pypy/rpython/rctypes/rchar_p.py
pypy/branch/kill-keepalives/pypy/rpython/rctypes/rmodel.py
pypy/branch/kill-keepalives/pypy/rpython/rctypes/rstruct.py
Log:
More keepalive fine-tuning. Tests still not passing.
Modified: pypy/branch/kill-keepalives/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/rpython/rctypes/rarray.py (original)
+++ pypy/branch/kill-keepalives/pypy/rpython/rctypes/rarray.py Sat Sep 16 19:08:54 2006
@@ -5,6 +5,7 @@
from pypy.annotation.pairtype import pairtype
from pypy.rpython.rctypes.rmodel import CTypesRefRepr, CTypesValueRepr
from pypy.rpython.rctypes.rmodel import genreccopy_arrayitem, reccopy, C_ZERO
+from pypy.rpython.rctypes.rmodel import copykeepalive
from pypy.rpython.rctypes.rprimitive import PrimitiveRepr
from pypy.rpython.rctypes.rpointer import PointerRepr
from pypy.rpython.rctypes.aarray import VarSizedArrayType
@@ -105,7 +106,9 @@
v_c_array = self.get_c_data(llops, v_array)
genreccopy_arrayitem(llops, v_newvalue, v_c_array, v_index)
# copy the keepalive information too
- self.r_item.copykeepalive(llops, v_item, v_array, (v_index,))
+ if hasattr(self.r_item.lowleveltype.TO, 'keepalive'):
+ copykeepalive(llops, self.r_item.lowleveltype.TO.keepalive,
+ v_item, (), v_array, (v_index,))
def initializeitems(self, llops, v_array, items_v):
for i, v_item in enumerate(items_v):
@@ -123,12 +126,16 @@
# NB. this optimization is invalid for PointerReprs! See for
# example: a[0].contents = ... to change the first pointer of
# an array of pointers.
- v_value = r_array.get_item_value(hop.llops, v_array, v_index)
- return r_array.r_item.return_value(hop.llops, v_value, v_owner)
+ v_c_data = r_array.get_item_value(hop.llops, v_array, v_index)
else:
# ByRef case
v_c_data = r_array.get_c_data_of_item(hop.llops, v_array, v_index)
- return r_array.r_item.return_c_data(hop.llops, v_c_data, v_owner)
+ v_item = r_array.r_item.return_c_data(hop.llops, v_c_data, v_owner)
+ # copy the keepalive information too
+ if hasattr(r_array.r_item.lowleveltype.TO, 'keepalive'):
+ copykeepalive(hop.llops, r_array.r_item.lowleveltype.TO.keepalive,
+ v_array, (v_index,), v_item, ())
+ return v_item
def rtype_setitem((r_array, r_int), hop):
v_array, v_index, v_item = hop.inputargs(r_array, lltype.Signed,
Modified: pypy/branch/kill-keepalives/pypy/rpython/rctypes/rchar_p.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/rpython/rctypes/rchar_p.py (original)
+++ pypy/branch/kill-keepalives/pypy/rpython/rctypes/rchar_p.py Sat Sep 16 19:08:54 2006
@@ -12,8 +12,6 @@
class CCharPRepr(CTypesValueRepr):
- autofree_fields = ("keepalive",)
-
def return_c_data(self, llops, v_c_data, v_c_data_owner):
"""Read out the RPython string from a raw C pointer.
Used when the data is returned from an operation or C function call.
Modified: pypy/branch/kill-keepalives/pypy/rpython/rctypes/rmodel.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/rpython/rctypes/rmodel.py (original)
+++ pypy/branch/kill-keepalives/pypy/rpython/rctypes/rmodel.py Sat Sep 16 19:08:54 2006
@@ -9,6 +9,7 @@
RCBOX_HEADER = lltype.GcStruct('rcbox',
('rtti', lltype.Ptr(lltype.RuntimeTypeInfo)))
P_RCBOX_HEADER = lltype.Ptr(RCBOX_HEADER)
+lltype.attachRuntimeTypeInfo(RCBOX_HEADER)
class CTypesRepr(Repr):
@@ -35,8 +36,6 @@
# * 'r_memoryowner.lowleveltype' is the lowleveltype of the repr for the
# same ctype but for ownsmemory=True.
- autofree_fields = ()
-
def __init__(self, rtyper, s_ctypesobject, ll_type):
# s_ctypesobject: the annotation to represent
# ll_type: the low-level type representing the raw
@@ -56,9 +55,10 @@
fields.append(( "keepalive", content_keepalive_type ))
if self.ownsmemory:
- self.autofree_fields = ("c_data",) + self.__class__.autofree_fields
+ self.autofree_fields = ("c_data",)
self.r_memoryowner = self
else:
+ self.autofree_fields = ()
s_memoryowner = SomeCTypesObject(ctype, ownsmemory=True)
self.r_memoryowner = rtyper.getrepr(s_memoryowner)
# the box that really owns our C data - it is usually a box of
@@ -104,6 +104,9 @@
lltype.attachRuntimeTypeInfo(self.lowleveltype.TO,
queryptr, destrptr)
+ # make sure the RCBOX_HEADER itself has got a query function
+ lltype.attachRuntimeTypeInfo(RCBOX_HEADER, queryptr)
+
def get_content_keepalive_type(self):
"""Return the type of the extra keepalive field used for the content
of this object."""
@@ -247,20 +250,6 @@
"""
return self.allocate_instance_ref(llops, v_c_data, v_c_data_owner)
- def copykeepalive(self, llops, v_box, v_destbox, destsuboffset=()):
- # copy the 'keepalive' data over, unless it's an autofree
- assert v_box.concretetype == self.lowleveltype
- try:
- TYPE = self.lowleveltype.TO.keepalive
- except AttributeError:
- pass
- else:
- if 'keepalive' not in self.autofree_fields:
- c_keepalive = inputconst(lltype.Void, 'keepalive')
- genreccopy_rel(llops, TYPE,
- v_box, (c_keepalive,),
- v_destbox, (c_keepalive,) + destsuboffset)
-
class __extend__(pairtype(CTypesRepr, CTypesRepr)):
@@ -271,9 +260,10 @@
r_from.ownsmemory and not r_to.ownsmemory):
v_c_data = r_from.get_c_data(llops, v)
v_result = r_to.allocate_instance_ref(llops, v_c_data, v)
- # copy the 'keepalive' information
- c_keepalive = inputconst(lltype.Void, 'keepalive')
- r_from.copykeepalive(llops, v, v_result)
+ # copy all the 'keepalive' information
+ if hasattr(r_from.lowleveltype.TO, 'keepalive'):
+ copykeepalive(llops, r_from.lowleveltype.TO.keepalive,
+ v, (), v_result, ())
return v_result
else:
return NotImplemented
@@ -352,6 +342,14 @@
resulttype=P_RCBOX_HEADER)
return v_box
+def copykeepalive(llops, TYPE, v_box, srcsuboffset,
+ v_destbox, destsuboffset):
+ # copy (a part of) the 'keepalive' data over
+ c_keepalive = inputconst(lltype.Void, 'keepalive')
+ genreccopy_rel(llops, TYPE,
+ v_box, (c_keepalive,) + srcsuboffset,
+ v_destbox, (c_keepalive,) + destsuboffset)
+
def reccopy(source, dest):
# copy recursively a structure or array onto another.
T = lltype.rawTypeOf(source).TO
Modified: pypy/branch/kill-keepalives/pypy/rpython/rctypes/rstruct.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/rpython/rctypes/rstruct.py (original)
+++ pypy/branch/kill-keepalives/pypy/rpython/rctypes/rstruct.py Sat Sep 16 19:08:54 2006
@@ -2,6 +2,7 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.rctypes.rmodel import CTypesRefRepr, CTypesValueRepr
from pypy.rpython.rctypes.rmodel import genreccopy_structfield, reccopy
+from pypy.rpython.rctypes.rmodel import copykeepalive
from pypy.rpython.rctypes.rprimitive import PrimitiveRepr
from pypy.annotation.model import SomeCTypesObject
@@ -97,11 +98,17 @@
# example: s.p.contents = ... to change the pointer field 'p'
# of 's'.
v_value = self.get_field_value(hop.llops, v_struct, name)
- return r_field.return_value(hop.llops, v_value, v_owner)
+ v_item = r_field.return_value(hop.llops, v_value, v_owner)
else:
# ByRef case
v_c_data = self.get_c_data_of_field(hop.llops, v_struct, name)
- return r_field.return_c_data(hop.llops, v_c_data, v_owner)
+ v_item = r_field.return_c_data(hop.llops, v_c_data, v_owner)
+ # copy the keepalive information too
+ if hasattr(r_field.lowleveltype.TO, 'keepalive'):
+ c_name = inputconst(lltype.Void, cmangle(name))
+ copykeepalive(hop.llops, r_field.lowleveltype.TO.keepalive,
+ v_struct, (c_name,), v_item, ())
+ return v_item
def rtype_setattr(self, hop):
s_attr = hop.args_s[1]
@@ -118,8 +125,10 @@
v_c_struct = self.get_c_data(llops, v_struct)
genreccopy_structfield(llops, v_newvalue, v_c_struct, cmangle(name))
# copy the keepalive information too
- c_name = inputconst(lltype.Void, cmangle(name))
- r_field.copykeepalive(llops, v_item, v_struct, (c_name,))
+ if hasattr(r_field.lowleveltype.TO, 'keepalive'):
+ c_name = inputconst(lltype.Void, cmangle(name))
+ copykeepalive(llops, r_field.lowleveltype.TO.keepalive,
+ v_item, (), v_struct, (c_name,))
def cmangle(name):
# obscure: names starting with '_' are not allowed in
More information about the Pypy-commit
mailing list