diff options
author | Damien George <damien.p.george@gmail.com> | 2014-12-05 23:13:52 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-12-05 23:13:52 +0000 |
commit | be6d8be91e133e98117025062df0e63aaf87efd2 (patch) | |
tree | 692495154f547612c148312b4abc0afc3f4a50d6 /tests/basics/struct1.py | |
parent | 451a0870753be89f5a284fd39727705a3ad2109b (diff) |
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.
Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.
Addresses issues #779 and #998.
Diffstat (limited to 'tests/basics/struct1.py')
-rw-r--r-- | tests/basics/struct1.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index c3049c55d..cebffc142 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -25,3 +25,15 @@ print(struct.pack("<6sH", b"foo", 10000)) s = struct.pack("BHBI", 10, 100, 200, 300) v = struct.unpack("BHBI", s) print(v == (10, 100, 200, 300)) + +# check maximum pack on 32-bit machine +print(struct.pack("<I", 2**32 - 1)) +print(struct.pack("<I", 0xffffffff)) + +# fails on 32-bit machine +#print(struct.pack("<Q", 2**64 - 1)) +#print(struct.pack("<Q", 0xffffffffffffffff)) + +# check maximum unpack +print(struct.unpack("<I", b"\xff\xff\xff\xff")) +print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff")) |