Wykres commitów

2 Commity (fd7bc4f12bcb3a702cb1db6d19e4258ad854b7f6)

Autor SHA1 Wiadomość Data
Angus Gratton fd7bc4f12b WIP: objint: Support signed parameter for int.to_bytes().
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-10 14:20:23 +10:00
Angus Gratton c97d3534dc py/objint: Fix int.to_bytes() buffer size checks.
* No longer overflows if byte size is 0 (closes #13041)
* Raises OverflowError in any case where number won't fit into byte length
  (Now matches CPython, previously MicroPython would return a truncated
  bytes object.)
* Document that micropython int.to_bytes() doesn't implement the optional
  signed kwarg, but will behave as if signed=True when the integer is
  negative (this is the current behaviour). Add tests for this also.

Requires changes for small ints, MPZ large ints, and "long long" large
ints.

Adds a new set of unit tests for ints between 32 and 64 bits to increase
coverage of "long long" large ints, which are otherwise untested.

Tested on unix port (64 bit small ints, MPZ long ints) and Zephyr STM32WB
board (32 bit small ints, long long large ints).

Untested on a port whose native format is big endian (don't have one at
hand).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-10 13:52:29 +10:00