Serhiy Storchaka added the comment:
_Py_Uid_Converter() in Modules/posixmodule.c is not an example because it calls
PyLong_AsUnsignedLong() only for positive integers > LONG_MAX.
PyLong_AsUnsignedLong() is used not much. The motivation of this issue was that
if use PyLong_AsUnsignedLong() for
Raymond Hettinger added the comment:
Looking back in time, this API isn't as old as I thought. The other concerns
about breaking a published API still stand.
--
nosy: -gvanrossum
___
Python tracker
Raymond Hettinger added the comment:
Strong -1 on this. For zero benefit, this breaks everything (within Python and
third-party code) that ever relied on the documented behavior ,
https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLong .
The cause perfectly fits the definition of
Oren Milman added the comment:
note that there are functions that rely on the fact that
PyLong_AsUnsignedLong currently raises OverflowError for both cases.
such functions would probably use
PyErr_ExceptionMatches(PyExc_OverflowError)
or something like
PyErr_GivenExceptionMatches(err,
New submission from Serhiy Storchaka:
OverflowError is raised when Python integer doesn't fit in C integer type due
to platform limitations. Different platforms have different limits. But in
PyLong_AsUnsignedLong() only the upper limit is platform-depended. Negative
integers always are not