1. Python CFFI
  2. Untitled project
  3. cffi

Commits

Armin Rigo  committed 8d3d149

A bytearray doesn't work, by design. If you really want one, you
can do buffer(p)[:] = ...

  • Participants
  • Parent commits f60f68a
  • Branches default

Comments (0)

Files changed (1)

File c/test_c.py

View file
     p = newp(BSCharArray, b"fo\xff")
     assert len(p) == 4
     assert list(p) == [ord("f"), ord("o"), -1, 0]
+
+def test_newp_from_bytearray_doesnt_work():
+    BCharArray = new_array_type(
+        new_pointer_type(new_primitive_type("char")), None)
+    py.test.raises(TypeError, newp, BCharArray, bytearray(b"foo"))
+    p = newp(BCharArray, 4)
+    buffer(p)[:] = bytearray(b"foo\x00")
+    assert len(p) == 4
+    assert list(p) == [b"f", b"o", b"o", b"\x00"]