extmod/moductypes: Fix storing to (U)INT64 arrays on 32-bit archs.

Fixes issue #6583.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2020-11-05 22:39:54 +11:00
parent 1fef5662ab
commit bdfb584b29
3 changed files with 44 additions and 1 deletions

View File

@ -399,7 +399,7 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
((uint64_t *)p)[index] = (uint64_t)v;
} else {
// TODO: Doesn't offer atomic store semantics, but should at least try
set_unaligned(val_type, p, MP_ENDIANNESS_BIG, val);
set_unaligned(val_type, (void *)&((uint64_t *)p)[index], MP_ENDIANNESS_BIG, val);
}
return;
default:

View File

@ -0,0 +1,19 @@
# Test uctypes array, load and store, with array size > 1
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
N = 3
for endian in ("NATIVE", "LITTLE_ENDIAN", "BIG_ENDIAN"):
for type_ in ("INT8", "UINT8", "INT16", "UINT16", "INT32", "UINT32", "INT64", "UINT64"):
desc = {"arr": (uctypes.ARRAY | 0, getattr(uctypes, type_) | N)}
sz = uctypes.sizeof(desc)
data = bytearray(sz)
s = uctypes.struct(uctypes.addressof(data), desc, getattr(uctypes, endian))
for i in range(N):
s.arr[i] = i
print(endian, type_, sz, *(s.arr[i] for i in range(N)))

View File

@ -0,0 +1,24 @@
NATIVE INT8 3 0 1 2
NATIVE UINT8 3 0 1 2
NATIVE INT16 6 0 1 2
NATIVE UINT16 6 0 1 2
NATIVE INT32 12 0 1 2
NATIVE UINT32 12 0 1 2
NATIVE INT64 24 0 1 2
NATIVE UINT64 24 0 1 2
LITTLE_ENDIAN INT8 3 0 1 2
LITTLE_ENDIAN UINT8 3 0 1 2
LITTLE_ENDIAN INT16 6 0 1 2
LITTLE_ENDIAN UINT16 6 0 1 2
LITTLE_ENDIAN INT32 12 0 1 2
LITTLE_ENDIAN UINT32 12 0 1 2
LITTLE_ENDIAN INT64 24 0 1 2
LITTLE_ENDIAN UINT64 24 0 1 2
BIG_ENDIAN INT8 3 0 1 2
BIG_ENDIAN UINT8 3 0 1 2
BIG_ENDIAN INT16 6 0 1 2
BIG_ENDIAN UINT16 6 0 1 2
BIG_ENDIAN INT32 12 0 1 2
BIG_ENDIAN UINT32 12 0 1 2
BIG_ENDIAN INT64 24 0 1 2
BIG_ENDIAN UINT64 24 0 1 2