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.
This commit is contained in:
committed by
Damien George
parent
12f13ee634
commit
1022f9cc35
17
tests/basics/struct_endian.py
Normal file
17
tests/basics/struct_endian.py
Normal file
@@ -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))
|
||||
Reference in New Issue
Block a user