[pypy-svn] pypy jitypes2: hoorray, it is now possible to pass structures by value
antocuni
commits-noreply at bitbucket.org
Tue Dec 28 09:31:15 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40251:e55ede923f1a
Date: 2010-12-28 09:21 +0100
http://bitbucket.org/pypy/pypy/changeset/e55ede923f1a/
Log: hoorray, it is now possible to pass structures by value
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -247,9 +247,12 @@
try:
return self._typemap[shape]
except KeyError:
- print 'unknown shape %s' % (shape,)
- assert False, 'TODO5'
-
+ pass
+ if self._is_struct_shape(shape):
+ return shape[0].get_ffi_type()
+ #
+ print 'unknown shape %s' % (shape,)
+ assert False, 'TODO5'
def _getfuncptr(self, argtypes, restype, thisarg=None):
if self._ptr is not None and argtypes is self._argtypes_:
@@ -391,6 +394,7 @@
"""
assert len(argtypes) == len(args)
newargs = []
+ # XXX: investigate the difference between _ffishape and _ffiargshape
for argtype, arg in zip(argtypes, args):
if argtype._ffishape == 'u':
# XXX: who should do this conversion? Maybe _ffi?
@@ -401,11 +405,20 @@
value = arg._get_buffer_value()
elif argtype._ffishape == 'z':
value = arg._get_buffer_value()
+ elif self._is_struct_shape(arg._ffiargshape):
+ value = arg._get_buffer_value()
else:
value = arg.value
newargs.append(value)
return newargs
+ def _is_struct_shape(self, _ffishape):
+ # see the corresponding code to set the shape in _ctypes.structure._set_shape
+ return (isinstance(_ffishape, tuple) and
+ len(_ffishape) == 2 and
+ isinstance(_ffishape[0], _rawffi.Structure) and
+ _ffishape[1] == 1)
+
def _wrap_result(self, restype, result):
"""
Convert from low-level repr of the result to the high-level python
More information about the Pypy-commit
mailing list