Skip to content

Commit db0f5d4

Browse files
committed
GR-26868: _struct: fix native format sizing and overflow handling for unsigned longs
1 parent 8724ab1 commit db0f5d4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_struct.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ def test_pack_unpack():
145145
def test_pack_nan():
146146
import math
147147
assert struct.pack('<d', math.nan) == b'\x00\x00\x00\x00\x00\x00\xf8\x7f'
148+
149+
150+
def test_pack_large_long():
151+
for fmt in ('l', 'q'):
152+
assert struct.pack(fmt, 0) == b'\x00\x00\x00\x00\x00\x00\x00\x00'
153+
assert struct.unpack(fmt, b'\x00\x00\x00\x00\x00\x00\x00\x00') == (0,)
154+
assert struct.pack(fmt, -1) == b'\xff\xff\xff\xff\xff\xff\xff\xff'
155+
assert struct.unpack(fmt, b'\xff\xff\xff\xff\xff\xff\xff\xff') == (-1,)
156+
157+
for fmt in ('L', 'Q'):
158+
assert struct.pack(fmt, 0) == b'\x00\x00\x00\x00\x00\x00\x00\x00'
159+
assert struct.unpack(fmt, b'\x00\x00\x00\x00\x00\x00\x00\x00') == (0,)
160+
assert struct.pack(fmt, 18446744073709551615) == b'\xff\xff\xff\xff\xff\xff\xff\xff'
161+
assert struct.unpack(fmt, b'\xff\xff\xff\xff\xff\xff\xff\xff') == (18446744073709551615,)

0 commit comments

Comments
 (0)