`PyNumber_ToBase` fails for numbers not representable by a `long long`
PyNumber_ToBase
converts a Python int
to a str
in the specified base. Note that the description of the function makes no mention of a potential OverflowError
, i.e. it would be expected to make this conversion for arbitrarily large numbers. However, as of PyPy3.8 7.3.7, that exception is exactly what happens if the value lies outside the range of a long long
, i.e. [-2**63, 2**63-1]
:
OverflowError: int too large to convert to int
str(value)
works fine for any int, of course, and that is what _int_to_base
calls for base-10. This suggests that there is an issue in PyNumber_ToBase
itself. However, for other bases, _int_to_base
would presumably also fail for large ints given that it calls r_uint
.
Side note: I also discovered that there are no tests for such inputs in CPython's test suite, which I believe PyPy is using as well. I suspect that this contributed to this bug not being discovered sooner. Filed upstream: https://github.com/python/cpython/issues/93884