Skip to content

Commit 6e4c263

Browse files
committed
[GR-26868] _struct: fix native format sizing and overflow handling for unsigned longs
PullRequest: graalpython/1347
2 parents 90ab65a + f5d36a0 commit 6e4c263

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' * struct.calcsize(fmt)
153+
assert struct.unpack(fmt, b'\x00' * struct.calcsize(fmt)) == (0,)
154+
assert struct.pack(fmt, -1) == b'\xff' * struct.calcsize(fmt)
155+
assert struct.unpack(fmt, b'\xff' * struct.calcsize(fmt)) == (-1,)
156+
157+
for fmt in ('L', 'Q'):
158+
assert struct.pack(fmt, 0) == b'\x00' * struct.calcsize(fmt)
159+
assert struct.unpack(fmt, b'\x00' * struct.calcsize(fmt)) == (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)