gh-108444: Add PyLong_AsInt() public function (#108445)

* Rename _PyLong_AsInt() to PyLong_AsInt().
* Add documentation.
* Add test.
* For now, keep _PyLong_AsInt() as an alias to PyLong_AsInt().
This commit is contained in:
Victor Stinner 2023-08-24 23:55:30 +02:00 committed by GitHub
parent feb9a49c9c
commit be436e08b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 96 additions and 3 deletions

View file

@ -136,6 +136,14 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
This function will no longer use :meth:`~object.__int__`.
.. c:function:: int PyLong_AsInt(PyObject *obj)
Similar to :c:func:`PyLong_AsLong`, but store the result in a C
:c:expr:`int` instead of a C :c:expr:`long`.
.. versionadded:: 3.13
.. c:function:: long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow)
Return a C :c:expr:`long` representation of *obj*. If *obj* is not an

View file

@ -347,6 +347,7 @@ var,PyList_Type,3.2,,
type,PyLongObject,3.2,,opaque
var,PyLongRangeIter_Type,3.2,,
function,PyLong_AsDouble,3.2,,
function,PyLong_AsInt,3.13,,
function,PyLong_AsLong,3.2,,
function,PyLong_AsLongAndOverflow,3.2,,
function,PyLong_AsLongLong,3.2,,

View file

@ -871,6 +871,12 @@ New Features
:term:`shutting down <interpreter shutdown>`.
(Contributed by Victor Stinner in :gh:`108014`.)
* Add :c:func:`PyLong_AsInt` function: similar to :c:func:`PyLong_AsLong`, but
store the result in a C :c:expr:`int` instead of a C :c:expr:`long`.
Previously, it was known as the private function :c:func:`!_PyLong_AsInt`
(with an underscore prefix).
(Contributed by Victor Stinner in :gh:`108014`.)
Porting to Python 3.13
----------------------