diff options
author | Tom McDermott <spon@wattwatchers.com.au> | 2019-08-05 15:15:28 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-09-02 13:10:55 +1000 |
commit | 1022f9cc35564b216a4bcd7c65e8243c810a0ca9 (patch) | |
tree | bc2d7d12d447a63f6a4c1c9e0f862a616a9b9a80 /tests/basics/struct_endian.py | |
parent | 12f13ee6346d8fd029fc2ecec06d50b5f7f6b252 (diff) |
py/modstruct: Fix struct.unpack with unaligned offset of native type.
With this patch alignment is done relative to the start of the buffer that
is being unpacked, not the raw pointer value, as per CPython.
Fixes issue #3314.
Diffstat (limited to 'tests/basics/struct_endian.py')
-rw-r--r-- | tests/basics/struct_endian.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/basics/struct_endian.py b/tests/basics/struct_endian.py new file mode 100644 index 000000000..ae3243824 --- /dev/null +++ b/tests/basics/struct_endian.py @@ -0,0 +1,17 @@ +# test ustruct and endian specific things + +try: + import ustruct as struct +except: + try: + import struct + except ImportError: + print("SKIP") + raise SystemExit + +# unpack/unpack_from with unaligned native type +buf = b'0123456789' +print(struct.unpack('h', memoryview(buf)[1:3])) +print(struct.unpack_from('i', buf, 1)) +print(struct.unpack_from('@i', buf, 1)) +print(struct.unpack_from('@ii', buf, 1)) |