Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/execnet/gateway_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ def bchr(n: int) -> bytes:
DUMPFORMAT_VERSION = bchr(2)

FOUR_BYTE_INT_MAX = 2147483647
FOUR_BYTE_INT_MIN = -2147483648

FLOAT_FORMAT = "!d"
FLOAT_FORMAT_SIZE = struct.calcsize(FLOAT_FORMAT)
Expand Down Expand Up @@ -1693,7 +1694,7 @@ def _write_byte_sequence(self, bytes_: bytes) -> None:
self._write(bytes_)

def _save_integral(self, i: int, short_op: bytes, long_op: bytes) -> None:
if i <= FOUR_BYTE_INT_MAX:
if FOUR_BYTE_INT_MIN <= i <= FOUR_BYTE_INT_MAX:
self._write(short_op)
self._write_int4(i)
else:
Expand All @@ -1717,7 +1718,7 @@ def save_complex(self, cpx: complex) -> None:
def _write_int4(
self, i: int, error: str = "int must be less than %i" % (FOUR_BYTE_INT_MAX,)
) -> None:
if i > FOUR_BYTE_INT_MAX:
if not FOUR_BYTE_INT_MIN <= i <= FOUR_BYTE_INT_MAX:
raise DumpError(error)
self._write(struct.pack("!i", i))

Expand Down
4 changes: 3 additions & 1 deletion testing/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
)


@pytest.mark.parametrize("val", ["123", 42, [1, 2, 3], ["23", 25]])
@pytest.mark.parametrize(
"val", ["123", 42, [1, 2, 3], ["23", 25], 2**31, -(2**31) - 1, 10**30, -(10**30)]
)
class TestSerializeAPI:
def test_serializer_api(self, val: object) -> None:
dumped = execnet.dumps(val)
Expand Down
9 changes: 9 additions & 0 deletions testing/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ def test_long(load, dump) -> None:
assert v == really_big


def test_negative_long(load, dump) -> None:
# anything below the 4-byte range must take the long path, like big positives do
really_small = "-9223372036854775807324234"
p = dump(really_small)
tp, v = load(p)
assert tp == "int"
assert v == really_small


def test_bytes(dump, load) -> None:
p = dump("b'hi'")
tp, v = load(p)
Expand Down