[pypy-commit] pypy default: Fixed segfault in test_ctypes_support.test_argument_conversion_and_checks

wilberforce noreply at buildbot.pypy.org
Sat Jun 25 19:14:46 CEST 2011


Author: Christian Muirhead <xtian at babbageclunk.com>
Branch: 
Changeset: r45123:b28cc6f1e4b3
Date: 2011-06-25 19:18 +0200
http://bitbucket.org/pypy/pypy/changeset/b28cc6f1e4b3/

Log:	Fixed segfault in
	test_ctypes_support.test_argument_conversion_and_checks

diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py
--- a/pypy/module/_ffi/interp_ffi.py
+++ b/pypy/module/_ffi/interp_ffi.py
@@ -217,7 +217,7 @@
         if meth:
             return space.call_function(meth, w_arg, w_argtype)
         else:
-            return w_arg
+            raise OperationError(space.w_TypeError, space.wrap('not an ffi pointer type'))
 
     @jit.dont_look_inside
     def arg_longlong(self, space, argchain, kind, w_arg):
diff --git a/pypy/module/_ffi/test/test__ffi.py b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -139,32 +139,13 @@
         assert get_dummy() == 42
         set_dummy(0)
 
-    def test_pointer_args(self):
+    def test_convert_pointer_args(self):
         """
             extern int dummy; // defined in test_void_result 
             DLLEXPORT int* get_dummy_ptr() { return &dummy; }
             DLLEXPORT void set_val_to_ptr(int* ptr, int val) { *ptr = val; }
         """
         from _ffi import CDLL, types
-        libfoo = CDLL(self.libfoo_name)
-        get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
-        get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], types.void_p)
-        set_val_to_ptr = libfoo.getfunc('set_val_to_ptr',
-                                        [types.void_p, types.sint],
-                                        types.void)
-        assert get_dummy() == 0
-        ptr = get_dummy_ptr()
-        set_val_to_ptr(ptr, 123)
-        assert get_dummy() == 123
-        set_val_to_ptr(ptr, 0)
-
-    def test_convert_pointer_args(self):
-        """
-            extern int dummy; // defined in test_void_result 
-            DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
-            DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
-        """
-        from _ffi import CDLL, types
 
         class MyPointerWrapper(object):
             def __init__(self, value):
@@ -213,11 +194,19 @@
 
         libfoo = CDLL(self.libfoo_name)
         intptr = types.Pointer(types.sint)
+
+        class MyPointerWrapper(object):
+            def __init__(self, value):
+                self.value = value
+            def _as_ffi_pointer_(self, ffitype):
+                assert ffitype is intptr
+                return self.value
+        
         get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
         get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], intptr)
         set_val_to_ptr = libfoo.getfunc('set_val_to_ptr', [intptr, types.sint], types.void)
         assert get_dummy() == 0
-        ptr = get_dummy_ptr()
+        ptr = MyPointerWrapper(get_dummy_ptr())
         set_val_to_ptr(ptr, 123)
         assert get_dummy() == 123
         set_val_to_ptr(ptr, 0)
@@ -230,8 +219,16 @@
         import sys
         from _ffi import CDLL, types
         libfoo = CDLL(self.libfoo_name)
+
+        class MyPointerWrapper(object):
+            def __init__(self, value):
+                self.value = value
+            def _as_ffi_pointer_(self, ffitype):
+                assert ffitype is types.void_p
+                return self.value
+
         is_null_ptr = libfoo.getfunc('is_null_ptr', [types.void_p], types.ulong)
-        assert not is_null_ptr(sys.maxint+1)
+        assert not is_null_ptr(MyPointerWrapper(sys.maxint+1))
 
     def test_unsigned_long_args(self):
         """


More information about the pypy-commit mailing list