summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-01-19 10:23:34 +0100
committerArmin Rigo <arigo@tunes.org>2020-01-19 10:23:34 +0100
commit4840f2bf291dfa58af123768a66b1a49e3af31a4 (patch)
treea16e1b0cccad87e87267dd092cdd2f79a4380653 /testing
parent7c871d4fe57e7f6c5d034b22326bc439aa6c6538 (diff)
downloadcffi-4840f2bf291dfa58af123768a66b1a49e3af31a4.tar.gz
Issue #440
Limit the amount of memory that is requested from alloca() for temporary conversion of arguments. Non-small requests are instead handled with PyObject_Malloc() and PyObject_Free().
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi0/test_function.py13
-rw-r--r--testing/cffi0/test_verify.py10
-rw-r--r--testing/cffi1/test_recompiler.py10
3 files changed, 33 insertions, 0 deletions
diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py
index d1f9ce4..6312707 100644
--- a/testing/cffi0/test_function.py
+++ b/testing/cffi0/test_function.py
@@ -520,3 +520,16 @@ class TestFunction(object):
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
ffi.dlclose(lib) # does not raise
+
+ def test_passing_large_list(self):
+ if self.Backend is CTypesBackend:
+ py.test.skip("the ctypes backend doesn't support this")
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ void getenv(char *);
+ """)
+ needs_dlopen_none()
+ m = ffi.dlopen(None)
+ arg = [b"F", b"O", b"O"] + [b"\x00"] * 20000000
+ x = m.getenv(arg)
+ assert x is None
diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py
index 52ce214..3a1c0b9 100644
--- a/testing/cffi0/test_verify.py
+++ b/testing/cffi0/test_verify.py
@@ -2550,3 +2550,13 @@ def test_arithmetic_in_cdef():
""".replace('?', str(a)))
# the verify() crashes if the values in the enum are different from
# the values we computed ourselves from the cdef()
+
+def test_passing_large_list():
+ ffi = FFI()
+ ffi.cdef("""void passing_large_list(long[]);""")
+ lib = ffi.verify("""
+ static void passing_large_list(long a[]) { }
+ """)
+ arg = list(range(20000000))
+ lib.passing_large_list(arg)
+ # assert did not segfault
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index 1b837f8..78abaa0 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -2445,3 +2445,13 @@ def test_struct_with_func_with_struct_arg():
};
""")
py.test.raises(RuntimeError, ffi.new, "struct BinaryTree *")
+
+def test_passing_large_list():
+ ffi = FFI()
+ ffi.cdef("""void passing_large_list(long[]);""")
+ lib = verify(ffi, "test_passing_large_list", """
+ static void passing_large_list(long a[]) { }
+ """)
+ arg = list(range(20000000))
+ lib.passing_large_list(arg)
+ # assert did not segfault