Issue #12965: More PyLong_As* clarifications. Thanks Stefan Krah.

This commit is contained in:
Mark Dickinson 2012-06-23 12:12:52 +01:00
parent f0acfeeccf
commit b8dc3ab08b
1 changed files with 39 additions and 22 deletions

View File

@ -167,9 +167,11 @@ All integers are implemented as "long" integer objects of arbitrary size.
single: PY_SSIZE_T_MAX single: PY_SSIZE_T_MAX
single: OverflowError (built-in exception) single: OverflowError (built-in exception)
Return a C :c:type:`Py_ssize_t` representation of the contents of *pylong*. Return a C :c:type:`Py_ssize_t` representation of *pylong*. *pylong* must
If *pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` be an instance of :c:type:`PyLongObject`.
is raised and ``-1`` will be returned.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
:c:type:`Py_ssize_t`.
.. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong) .. c:function:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
@ -178,16 +180,20 @@ All integers are implemented as "long" integer objects of arbitrary size.
single: ULONG_MAX single: ULONG_MAX
single: OverflowError (built-in exception) single: OverflowError (built-in exception)
Return a C :c:type:`unsigned long` representation of the contents of *pylong*. Return a C :c:type:`unsigned long` representation of *pylong*. *pylong*
If *pylong* is greater than :const:`ULONG_MAX`, an :exc:`OverflowError` is must be an instance of :c:type:`PyLongObject`.
raised.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
:c:type:`unsigned long`.
.. c:function:: size_t PyLong_AsSize_t(PyObject *pylong) .. c:function:: size_t PyLong_AsSize_t(PyObject *pylong)
Return a :c:type:`size_t` representation of the contents of *pylong*. If Return a C :c:type:`size_t` representation of of *pylong*. *pylong* must be
*pylong* is greater than the maximum value for a :c:type:`size_t`, an an instance of :c:type:`PyLongObject`.
:exc:`OverflowError` is raised.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
:c:type:`size_t`.
.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong) .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
@ -195,32 +201,43 @@ All integers are implemented as "long" integer objects of arbitrary size.
.. index:: .. index::
single: OverflowError (built-in exception) single: OverflowError (built-in exception)
Return a C :c:type:`unsigned long long` from a Python integer. If Return a C :c:type:`unsigned PY_LONG_LONG` representation of of *pylong*.
*pylong* cannot be represented as an :c:type:`unsigned long long`, *pylong* must be an instance of :c:type:`PyLongObject`.
an :exc:`OverflowError` is raised and ``(unsigned long long)-1`` is
returned. Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
:c:type:`unsigned PY_LONG_LONG`.
.. versionchanged:: 3.1 .. versionchanged:: 3.1
A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`. A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
.. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *io) .. c:function:: unsigned long PyLong_AsUnsignedLongMask(PyObject *obj)
Return a C :c:type:`unsigned long` from a Python integer, without checking for Return a C :c:type:`unsigned long` representation of *obj*. If *obj*
overflow. is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__`
method (if present) to convert it to a :c:type:`PyLongObject`.
If the value of *obj* is out of range for an :c:type:`unsigned long`,
return the reduction of that value modulo :const:`ULONG_MAX + 1`.
.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *io) .. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *obj)
Return a C :c:type:`unsigned long long` from a Python integer, without Return a C :c:type:`unsigned long long` representation of *obj*. If *obj*
checking for overflow. is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__`
method (if present) to convert it to a :c:type:`PyLongObject`.
If the value of *obj* is out of range for an :c:type:`unsigned long long`,
return the reduction of that value modulo :const:`PY_ULLONG_MAX + 1`.
.. c:function:: double PyLong_AsDouble(PyObject *pylong) .. c:function:: double PyLong_AsDouble(PyObject *pylong)
Return a C :c:type:`double` representation of the contents of *pylong*. If Return a C :c:type:`double` representation of *pylong*. *pylong* must be
*pylong* cannot be approximately represented as a :c:type:`double`, an an instance of :c:type:`PyLongObject`.
:exc:`OverflowError` exception is raised and ``-1.0`` will be returned.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for a
:c:type:`double`.
.. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong) .. c:function:: void* PyLong_AsVoidPtr(PyObject *pylong)