Overflow converting -2147483648 to int when using MPZ
When MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ, calling mp_obj_get_int() for a Python variable that contains the value -2147483648 results in an overflow converting long int to machine word error.
If MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG instead, the conversion works OK.
Is the MPZ overflow check incorrect?
py/objint_longlong: Fix overflow check in mp_obj_int_get_checked.
Summary
This is to fix an outstanding TODO. The test cases is using a range expression, as this is available all builds, but mp_obj_get_int is used by various extmod where an overflow is more likely to occur.
Testing
The code is pretty simple, and has been tested on unix/longlong varient.
An test case has been added in CI tests.
Trade-offs and Alternatives
I am not sure that this exception is likely to occur in the MicroPython core code ,unless the Python code includes a serious bug. Therefore, the extra code size might not be worthwhile for everyone. However, there are many hardware extensions that use this function, and in those cases, the likelihood of an overflow is much higher.