Commit b26743eb authored by Armin Rigo's avatar Armin Rigo

explicit test of unaligned pointer reads/writes

parent 1d7c0e7d4cb0
......@@ -4496,3 +4496,24 @@ def test_type_available_with_correct_names():
tp = getattr(_cffi_backend, name)
assert isinstance(tp, type)
assert (tp.__module__, tp.__name__) == ('_cffi_backend', name)
def test_unaligned_types():
BByteArray = new_array_type(
new_pointer_type(new_primitive_type("unsigned char")), None)
pbuf = newp(BByteArray, 40)
buf = buffer(pbuf)
#
for name in ['short', 'int', 'long', 'long long', 'float', 'double',
'float _Complex', 'double _Complex']:
p = new_primitive_type(name)
if name.endswith(' _Complex'):
num = cast(p, 1.23 - 4.56j)
else:
num = cast(p, 0x0123456789abcdef)
size = sizeof(p)
buf[0:40] = b"\x00" * 40
pbuf1 = cast(new_pointer_type(p), pbuf + 1)
pbuf1[0] = num
assert pbuf1[0] == num
assert buf[0] == '\x00'
assert buf[1 + size] == '\x00'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment