[pypy-svn] pypy jitypes2: support for direct construction of fuctions by address. This makes
antocuni
commits-noreply at bitbucket.org
Mon Jan 3 11:06:27 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40334:11670acbcfdb
Date: 2011-01-03 11:05 +0100
http://bitbucket.org/pypy/pypy/changeset/11670acbcfdb/
Log: support for direct construction of fuctions by address. This makes
ctypes.memmove&co. working, and lets test_array.py to pass
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
@@ -2,6 +2,7 @@
from _ctypes.basics import _CData, _CDataMeta, cdata_from_address
from _ctypes.basics import ArgumentError, keepalive_key
import _rawffi
+import _ffi
import sys
import traceback
@@ -45,7 +46,8 @@
_needs_free = False
callable = None
_ptr = None
- _buffer = None
+ _buffer = None # XXX: maybe we should kill it when jitypes2 is complete
+ _address = None
# win32 COM properties
_paramflags = None
_com_index = None
@@ -115,10 +117,9 @@
if isinstance(argument, (int, long)):
# direct construction from raw address
- ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_)
- self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires,
- self._flags_)
- self._buffer = self._ptr.byptr()
+ argshapes, resshape = self._ffishapes(self._argtypes_, self._restype_)
+ self._address = argument
+ self._ptr = self._getfuncptr_fromaddress(self._address, argshapes, resshape)
elif callable(argument):
# A callback into python
self.callable = argument
@@ -253,6 +254,11 @@
print 'unknown shape %s' % (shape,)
assert False, 'TODO5'
+ def _getfuncptr_fromaddress(self, address, argshapes, resshape):
+ ffiargs = [self._shape_to_ffi_type(shape) for shape in argshapes]
+ ffires = self._shape_to_ffi_type(resshape)
+ return _ffi.FuncPtr.fromaddr(address, '', ffiargs, ffires)
+
def _getfuncptr(self, argtypes, restype, thisarg=None):
if self._ptr is not None and argtypes is self._argtypes_:
return self._ptr
@@ -261,7 +267,14 @@
restype = ctypes.c_int
argshapes = [arg._ffiargshape for arg in argtypes]
resshape = restype._ffiargshape
+ if self._address is not None:
+ ptr = self._getfuncptr_fromaddress(self._address, argshapes, resshape)
+ if argtypes is self._argtypes_:
+ self._ptr = ptr
+ return ptr
+
if self._buffer is not None:
+ assert False, 'TODO'
ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape,
self._flags_)
if argtypes is self._argtypes_:
More information about the Pypy-commit
mailing list