Commits

Armin Rigo committed 718e553

Import test_c and fix the test.

Comments (0)

Files changed (2)

pypy/module/_cffi_backend/ctypearray.py

         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):

pypy/module/_cffi_backend/test/_backend_test_c.py

     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")