[pypy-commit] pypy default: Managed to write a test for d75b6c67c8e3.

arigo pypy.commits at gmail.com
Thu Apr 13 06:50:55 EDT 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r91054:da1964eea7ad
Date: 2017-04-13 12:50 +0200
http://bitbucket.org/pypy/pypy/changeset/da1964eea7ad/

Log:	Managed to write a test for d75b6c67c8e3.

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
@@ -596,3 +596,37 @@
 
         get_data.errcheck = ret_list_p(1)
         assert get_data('testing!') == [-1, -2, -3, -4]
+
+    def test_issue2533(self):
+        import cffi
+        ffi = cffi.FFI()
+        ffi.cdef("int **fetchme(void);")
+        ffi.set_source("_x_cffi", """
+            int **fetchme(void)
+            {
+                static int a = 42;
+                static int *pa = &a;
+                return &pa;
+            }
+        """)
+        from rpython.tool.udir import udir
+        ffi.compile(verbose=True, tmpdir=str(udir))
+
+        import sys
+        sys.path.insert(0, str(udir))
+        try:
+            from _x_cffi import ffi, lib
+        finally:
+            sys.path.pop(0)
+        fetchme = ffi.addressof(lib, 'fetchme')
+        fetchme = int(ffi.cast("intptr_t", fetchme))
+
+        FN = CFUNCTYPE(POINTER(POINTER(c_int)))
+        ff = cast(fetchme, FN)
+
+        g = ff()
+        assert g.contents.contents.value == 42
+
+        h = c_int(43)
+        g[0] = pointer(h)     # used to crash here
+        assert g.contents.contents.value == 43


More information about the pypy-commit mailing list