Author: Armin Rigo <[email protected]>
Branch:
Changeset: r56716:718e553be910
Date: 2012-08-12 23:53 +0200
http://bitbucket.org/pypy/pypy/changeset/718e553be910/
Log: Import test_c and fix the test.
diff --git a/pypy/module/_cffi_backend/ctypearray.py
b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -79,6 +79,12 @@
self.convert_array_from_object(cdata, w_ob)
def convert_to_object(self, cdata):
+ if self.length < 0:
+ # we can't return a <cdata 'int[]'> here, because we don't
+ # know the length to give it. As a compromize, returns
+ # <cdata 'int *'> in this case.
+ self = self.ctptr
+ #
return cdataobj.W_CData(self.space, cdata, self)
def add(self, cdata, i):
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -940,6 +940,16 @@
stderr = ll.read_variable(BVoidP, "stderr")
assert stderr == cast(BVoidP, _testfunc(8))
+def test_read_variable_as_unknown_length_array():
+ if sys.platform == 'win32':
+ py.test.skip("untested")
+ BCharP = new_pointer_type(new_primitive_type("char"))
+ BArray = new_array_type(BCharP, None)
+ ll = find_and_load_library('c')
+ stderr = ll.read_variable(BArray, "stderr")
+ assert repr(stderr).startswith("<cdata 'char *' 0x")
+ # ^^ and not 'char[]', which is basically not allowed and would crash
+
def test_write_variable():
if sys.platform == 'win32':
py.test.skip("untested")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit