def test_string_from_char_array(self):
ffi = FFI(backend=self.Backend())
p = ffi.new("char[]", b"hello.")
p[5] = b'!'
assert ffi.string(p) == b"hello!"
p[6] = b'?'
assert ffi.string(p) == b"hello!?"
p[3] = b'\x00'
assert ffi.string(p) == b"hel"
assert ffi.string(p, 2) == b"he"
py.test.raises(IndexError, "p[7] = b'X'")
#
a = ffi.new("char[]", b"hello\x00world")
assert len(a) == 12
p = ffi.cast("char *", a)
assert ffi.string(p) == b'hello'
评论列表
文章目录