[issue39762] PyLong_AS_LONG missing from longobject.h

2020-03-04 Thread Petr Viktorin
Petr Viktorin added the comment: No, in Python 2 the PyInt object (`int` in Python 2) always did fit into a C long -- that was the underlying storage. If it didn't fit, a PyLong object (`long` in Python 2) was used. Python 3 doesn't have PyInt, it only has PyLong (`int` in Python 3).

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-03-04 Thread Enji Cooper
Enji Cooper 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

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
Enji Cooper added the comment: PyInt_AS_LONG doesn't exist on python 3, however: $ grep -r PyInt_AS_LONG /usr/include/ [/usr/include/python2.7/intobject.h:#define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival) The code smell for the pieces that use PyInt_AS_LONG seems a bit questionable

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Serhiy Storchaka
Serhiy Storchaka 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

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
Enji Cooper added the comment: @serhiy.storchaka: understood. Figured this would be a good errata note for others to potentially find in the future. -- ___ Python tracker

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Python 2 is no longer supported. -- nosy: +serhiy.storchaka resolution: -> out of date stage: -> resolved status: open -> closed ___ Python tracker

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
Enji Cooper added the comment: Workaround PR posted here: https://github.com/encukou/py3c/pull/28 -- ___ Python tracker ___ ___

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
Enji Cooper added the comment: For the record, this seems like it might be the only discrepancy, per the py3c project's exported PyInt APIs: $ for api in `awk '$2 ~ /^PyInt/ { print $3 }' include/py3c/compat.h`; do grep -q $api /usr/include/python2.7/longobject.h || echo $api; done

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
Enji Cooper added the comment: For the record, some projects (like Cython, pywin32) worked around this by adding a preprocessor alias, PyLong_AS_LONG -> PyInt_AS_LONG with python 2.x. -- ___ Python tracker

[issue39762] PyLong_AS_LONG missing from longobject.h

2020-02-26 Thread Enji Cooper
New submission from Enji Cooper : While trying to port python 2 C extension code forward to python 3, I noticed that the python 2.6 PyInt -> PyLong unification lacks a forward-compatible API for PyLong_AS_LONG. I'm not sure if this was intentional, but it is a slightly annoying wicket to