diff options
author | Armin Rigo <arigo@tunes.org> | 2020-09-23 14:15:05 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2020-09-23 14:15:05 +0200 |
commit | 6684ff8f9112b8dd7166b34ea0f916695fe7a26c (patch) | |
tree | a502b48e2223d45920e2aa92a02cf44b92640471 /c | |
parent | 1218de63583f205a34fec71bafd51ee60f19142e (diff) | |
download | cffi-6684ff8f9112b8dd7166b34ea0f916695fe7a26c.tar.gz |
explicit test of unaligned pointer reads/writes
Diffstat (limited to 'c')
-rw-r--r-- | c/test_c.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/c/test_c.py b/c/test_c.py index fa24676..95ca812 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -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' |