[issue39762] PyLong_AS_LONG missing from longobject.h

Serhiy Storchaka report at bugs.python.org
Wed Feb 26 15:02:42 EST 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

The reason why there was the PyInt_AS_LONG macro is that it is very simple and efficient. It never fails, because the value of the int object always fits in the C long. PyInt_AsLong is much slower. If you know that the object is int, you can use PyInt_AS_LONG for performance and simplicity.

In contrary, converting the long object to the C long value requires a loop and it can overflow. There is no reason to implement it as a macro. You can use the PyLong_AsLong function.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39762>
_______________________________________


More information about the Python-bugs-list mailing list