[issue39762] PyLong_AS_LONG missing from longobject.h

Enji Cooper report at bugs.python.org
Wed Mar 4 12:49:45 EST 2020


Enji Cooper <yaneurabeya 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.

Another note: this assertion holds generally true with contemporary hardware architectures (sizeof(long long) != sizeof(int)), but there are still 32-bit hardware/software architectures (ex: non-ARM64 capable ARM arches, i386, powerpc 32-bit, etc) that violate this constraint. 32-bit architectures are at risk of overflow with 32-bit values.

----------

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


More information about the Python-bugs-list mailing list