Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r54955:13a365d94abb
Date: 2012-05-07 19:56 -0700
http://bitbucket.org/pypy/pypy/changeset/13a365d94abb/
Log: further refactoring, seems to resolve the insanity of the except
blocks
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -64,7 +64,7 @@
def convert_argument(self, space, w_obj, address, call_local):
self._is_abstract(space)
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
raise FastCallNotPossible
@@ -159,9 +159,8 @@
_mixin_ = True
_immutable_ = True
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
argchain.arg(self._unwrap_object(space, w_obj))
- return lltype.nullptr(rffi.VOIDP.TO)
def default_argument_libffi(self, space, argchain):
argchain.arg(self.default)
@@ -181,13 +180,12 @@
_immutable_ = True
uses_local = True
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
+ assert rffi.sizeof(self.c_type) <= 2*rffi.sizeof(rffi.VOIDP) # see
interp_cppyy.py
obj = self._unwrap_object(space, w_obj)
- tbuf = lltype.malloc(self.c_ptrtype.TO, rffi.sizeof(self.c_type),
flavor='raw')
- tbuf[0] = obj
- vbuf = rffi.cast(rffi.VOIDP, tbuf)
- argchain.arg(vbuf)
- return vbuf
+ typed_buf = rffi.cast(self.c_ptrtype, call_local)
+ typed_buf[0] = obj
+ argchain.arg(call_local)
class IntTypeConverterMixin(NumericTypeConverterMixin):
_mixin_ = True
@@ -235,9 +233,8 @@
x = rffi.cast(rffi.LONGP, address)
x[0] = self._unwrap_object(space, w_obj)
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
argchain.arg(self._unwrap_object(space, w_obj))
- return lltype.nullptr(rffi.VOIDP.TO)
def from_memory(self, space, w_obj, w_pycppclass, offset):
address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj,
offset))
@@ -278,9 +275,8 @@
x = rffi.cast(rffi.CCHARP, address)
x[0] = self._unwrap_object(space, w_obj)
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
argchain.arg(self._unwrap_object(space, w_obj))
- return lltype.nullptr(rffi.VOIDP.TO)
def from_memory(self, space, w_obj, w_pycppclass, offset):
address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj,
offset))
@@ -461,7 +457,7 @@
libffitype = libffi.types.pointer
typecode = 'F'
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
raise FastCallNotPossible
@@ -515,9 +511,8 @@
ba = rffi.cast(rffi.CCHARP, address)
ba[capi.c_function_arg_typeoffset()] = 'a'
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
argchain.arg(get_rawobject(space, w_obj))
- return lltype.nullptr(rffi.VOIDP.TO)
class VoidPtrPtrConverter(TypeConverter):
_immutable_ = True
@@ -656,9 +651,8 @@
ba = rffi.cast(rffi.CCHARP, address)
ba[capi.c_function_arg_typeoffset()] = 'o'
- def convert_argument_libffi(self, space, w_obj, argchain):
+ def convert_argument_libffi(self, space, w_obj, argchain, call_local):
argchain.arg(self._unwrap_object(space, w_obj))
- return lltype.nullptr(rffi.VOIDP.TO)
def from_memory(self, space, w_obj, w_pycppclass, offset):
address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj,
offset))
diff --git a/pypy/module/cppyy/interp_cppyy.py
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -130,7 +130,7 @@
def _address_from_local_buffer(self, call_local, idx):
if not call_local:
return call_local
- stride = rffi.sizeof(rffi.VOIDP)
+ stride = 2*rffi.sizeof(rffi.VOIDP)
loc_idx = lltype.direct_ptradd(rffi.cast(rffi.CCHARP, call_local),
idx*stride)
return rffi.cast(rffi.VOIDP, loc_idx)
@@ -153,7 +153,7 @@
# some calls, e.g. for ptr-ptr or reference need a local array to
store data for
# the duration of the call
if [conv for conv in self.converters if conv.uses_local]:
- call_local = rffi.lltype.malloc(rffi.VOIDP.TO, len(args_w),
flavor='raw')
+ call_local = lltype.malloc(rffi.VOIDP.TO, 2*len(args_w),
flavor='raw')
else:
call_local = lltype.nullptr(rffi.VOIDP.TO)
@@ -181,21 +181,14 @@
argchain = libffi.ArgChain()
argchain.arg(cppthis)
i = len(self.arg_defs)
- refbuffers = []
- try:
- for i in range(len(args_w)):
- conv = self.converters[i]
- w_arg = args_w[i]
- refbuf = conv.convert_argument_libffi(self.space, w_arg,
argchain)
- if refbuf:
- refbuffers.append(refbuf)
- for j in range(i+1, len(self.arg_defs)):
- conv = self.converters[j]
- conv.default_argument_libffi(self.space, argchain)
- return self.executor.execute_libffi(self.space, self._libffifunc,
argchain)
- finally:
- for refbuf in refbuffers:
- lltype.free(refbuf, flavor='raw')
+ for i in range(len(args_w)):
+ conv = self.converters[i]
+ w_arg = args_w[i]
+ conv.convert_argument_libffi(self.space, w_arg, argchain,
call_local)
+ for j in range(i+1, len(self.arg_defs)):
+ conv = self.converters[j]
+ conv.default_argument_libffi(self.space, argchain)
+ return self.executor.execute_libffi(self.space, self._libffifunc,
argchain)
def _setup(self, cppthis):
self.converters = [converter.get_converter(self.space, arg_type,
arg_dflt)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit