Author: Antonio Cuni <anto.c...@gmail.com> Branch: jitypes2 Changeset: r44620:af450a431526 Date: 2011-06-01 14:15 +0200 http://bitbucket.org/pypy/pypy/changeset/af450a431526/
Log: fix the failing test, by checking that we can actually cast the pointer also for primitive types (and switch to the slow path in case we cannot) 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 @@ -680,7 +680,7 @@ funcptr = self._getfuncptr(argtypes, restype, thisarg) try: result = self._call_funcptr(funcptr, *args) - except TypeError: # XXX, should be FFITypeError + except (TypeError, ArgumentError): # XXX, should be FFITypeError assert self._slowpath_allowed return CFuncPtr.__call__(self, *args) return result diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py --- a/lib_pypy/_ctypes/pointer.py +++ b/lib_pypy/_ctypes/pointer.py @@ -117,13 +117,16 @@ contents = property(getcontents, setcontents) def _as_ffi_pointer_(self, ffitype): - my_ffitype = type(self).get_ffi_argtype() - # for now, we always allow types.pointer, else a lot of tests - # break. We need to rethink how pointers are represented, though - if my_ffitype.deref_pointer() != ffitype.deref_pointer() and \ - ffitype is not _ffi.types.void_p: - raise ArgumentError, "expected %s instance, got %s" % (type(self), ffitype) - return self._get_buffer_value() + return as_ffi_pointer(self, ffitype) + +def as_ffi_pointer(value, ffitype): + my_ffitype = type(value).get_ffi_argtype() + # for now, we always allow types.pointer, else a lot of tests + # break. We need to rethink how pointers are represented, though + if my_ffitype.deref_pointer() != ffitype.deref_pointer() and \ + ffitype is not _ffi.types.void_p: + raise ArgumentError, "expected %s instance, got %s" % (type(value), ffitype) + return value._get_buffer_value() def _cast_addr(obj, _, tp): if not (isinstance(tp, _CDataMeta) and tp._is_pointer_like()): diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py --- a/lib_pypy/_ctypes/primitive.py +++ b/lib_pypy/_ctypes/primitive.py @@ -9,7 +9,7 @@ CArgObject from _ctypes.builtin import ConvMode from _ctypes.array import Array -from _ctypes.pointer import _Pointer +from _ctypes.pointer import _Pointer, as_ffi_pointer class NULL(object): pass @@ -255,7 +255,7 @@ # make pointer-types compatible with the _ffi fast path if result._is_pointer_like(): def _as_ffi_pointer_(self, ffitype): - return self._get_buffer_value() + return as_ffi_pointer(self, ffitype) result._as_ffi_pointer_ = _as_ffi_pointer_ return result diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py @@ -219,7 +219,6 @@ assert not result.contents == 99 def test_convert_pointers(self): - py.test.skip("segfault") f = dll.deref_LP_c_char_p f.restype = c_char f.argtypes = [POINTER(c_char_p)] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit