tests/extmod/json_loads: Add test cases for LONGINT parse. #16931
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
These tests cover the use of
mp_obj_new_int_from_str_lenwhenmp_parse_num_integeroverlows the SMALLINT limit.I recently discovered that the
LONGLONGimplementation ofmp_obj_new_int_from_str_lenis broken. It does not take the sign into account, and assumes the string buffer is nul-terminated, which is wrong asmp_parse_num_integeris mostly used onvstrbuffers.However, there is currently no test case that checks for these specific aspects of overflow handling: when integration tests are run with MICROPY_LONGINT_IMPL set to MICROPY_LONGINT_IMPL_LONGLONG, all tests pass.
So this pull requests adds coverage for these corner cases.
As there is currently no variant that uses MICROPY_LONGINT_IMPL_LONGLONG in the standard integration tests, adding these test cases will not cause a build issue.
Adding a MICROPY_LONGINT_IMPL_LONGLONG variant to the integration tests and fixing the longlong parsing code should be discussed first and handled in separate pull requests, but at least these test cases will properly document the problematic cases.
Testing
This code test code has been tested on Unix ports (LONGLONG and MPZ).
With MPZ, the test case pass
With LONGLONG, the test case fails