Commits

Armin Rigo  committed e8ea9f4

Test and fix

  • Participants
  • Parent commits 818271d

Comments (0)

Files changed (2)

File ffi/backend_ctypes.py

                         len1 = init
                         init = None
                     else:
+                        extra_null = (kind == 'char' and isinstance(init, str))
                         init = tuple(init)
-                        len1 = len(init)
+                        len1 = len(init) + extra_null
                     self._ctype = BItem._ctype * len1
                 self._blob = self._ctype()
                 if init is not None:

File testing/backend_tests.py

         p[0] = '\xff'
         assert p[0] == '\xff'
         p = ffi.new("char[]", "abcd")
-        assert len(p) == 4
+        assert len(p) == 5
+        assert p[4] == '\x00'    # like in C, with:  char[] p = "abcd";
 
     def test_none_as_null(self):
         ffi = FFI(backend=self.Backend())