All integers are implemented as “long” integer objects of arbitrary size.
On error, most PyLong_As* APIs return (returntype)-1 which cannot be distinguished from a number. Use
to disambiguate.
typePyLongObject
Part of the
(as an opaque struct).This subtype of
represents a Python integer object.
PyLong_Type
Part of the
.This instance of
represents the Python integer type. This is the same object as
in the Python layer.
intPyLong_Check(
*p)
Return true if its argument is a
or a subtype of
. This function always succeeds.
intPyLong_CheckExact(
*p)
Return true if its argument is a
, but not a subtype of
. This function always succeeds.
*PyLong_FromLong(longv)
Return value: New reference. Part of the
.Return a new
object from v, or NULL on failure.
The current implementation keeps an array of integer objects for all integers between -5 and 256. When you create an int in that range you actually just get back a reference to the existing object.
*PyLong_FromUnsignedLong(unsignedlongv)
Return value: New reference. Part of the
.Return a new
object from a C unsignedlong, or NULL on failure.
*PyLong_FromSsize_t(
v)
Return value: New reference. Part of the
.Return a new
object from a C
, or NULL on failure.
*PyLong_FromSize_t(size_tv)
Return value: New reference. Part of the
.Return a new
object from a C size_t, or NULL on failure.
*PyLong_FromLongLong(longlongv)
Return value: New reference. Part of the
.Return a new
object from a C longlong, or NULL on failure.
*PyLong_FromUnsignedLongLong(unsignedlonglongv)
Return value: New reference. Part of the
.Return a new
object from a C unsignedlonglong, or NULL on failure.
*PyLong_FromDouble(doublev)
Return value: New reference. Part of the
.Return a new
object from the integer part of v, or NULL on failure.
*PyLong_FromString(constchar*str, char**pend, intbase)
Return value: New reference. Part of the
.Return a new
based on the string value in str, which is interpreted according to the radix in base. If pend is non-NULL, *pend will point to the first character in str which follows the representation of the number. If base is 0, str is interpreted using the
definition; in this case, leading zeros in a non-zero decimal number raises a
. If base is not 0, it must be between 2 and 36, inclusive. Leading spaces and single underscores after a base specifier and between digits are ignored. If there are no digits,
will be raised.
*PyLong_FromUnicodeObject(
*u, intbase)
Return value: New reference.Convert a sequence of Unicode digits in the string u to a Python integer value.
New in version 3.3.
*PyLong_FromVoidPtr(void*p)
Return value: New reference. Part of the
.Create a Python integer from the pointer p. The pointer value can be retrieved from the resulting value using
.
longPyLong_AsLong(
*obj)
Part of the
.Return a C long representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
Raise
if the value of obj is out of range for a long.
Returns -1 on error. Use
to disambiguate.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
longPyLong_AsLongAndOverflow(
*obj, int*overflow)
Part of the
.Return a C long representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
If the value of obj is greater than LONG_MAX or less than LONG_MIN, set *overflow to 1 or -1, respectively, and return -1; otherwise, set *overflow to 0. If any other exception occurs set *overflow to 0 and return -1 as usual.
Returns -1 on error. Use
to disambiguate.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
longlongPyLong_AsLongLong(
*obj)
Part of the
.Return a C longlong representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
Raise
if the value of obj is out of range for a longlong.
Returns -1 on error. Use
to disambiguate.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
longlongPyLong_AsLongLongAndOverflow(
*obj, int*overflow)
Part of the
.Return a C longlong representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
If the value of obj is greater than LLONG_MAX or less than LLONG_MIN, set *overflow to 1 or -1, respectively, and return -1; otherwise, set *overflow to 0. If any other exception occurs set *overflow to 0 and return -1 as usual.
Returns -1 on error. Use
to disambiguate.
New in version 3.2.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
PyLong_AsSsize_t(
*pylong)
Part of the
.Return a C
representation of pylong. pylong must be an instance of
.
Raise
if the value of pylong is out of range for a
.
Returns -1 on error. Use
to disambiguate.
unsignedlongPyLong_AsUnsignedLong(
*pylong)
Part of the
.Return a C unsignedlong representation of pylong. pylong must be an instance of
.
Raise
if the value of pylong is out of range for a unsignedlong.
Returns (unsignedlong)-1 on error. Use
to disambiguate.
size_tPyLong_AsSize_t(
*pylong)
Part of the
.Return a C size_t representation of pylong. pylong must be an instance of
.
Raise
if the value of pylong is out of range for a size_t.
Returns (size_t)-1 on error. Use
to disambiguate.
unsignedlonglongPyLong_AsUnsignedLongLong(
*pylong)
Part of the
.Return a C unsignedlonglong representation of pylong. pylong must be an instance of
.
Raise
if the value of pylong is out of range for an unsignedlonglong.
Returns (unsignedlonglong)-1 on error. Use
to disambiguate.
unsignedlongPyLong_AsUnsignedLongMask(
*obj)
Part of the
.Return a C unsignedlong representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
If the value of obj is out of range for an unsignedlong, return the reduction of that value modulo ULONG_MAX+1.
Returns (unsignedlong)-1 on error. Use
to disambiguate.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
unsignedlonglongPyLong_AsUnsignedLongLongMask(
*obj)
Part of the
.Return a C unsignedlonglong representation of obj. If obj is not an instance of
, first call its
method (if present) to convert it to a
.
If the value of obj is out of range for an unsignedlonglong, return the reduction of that value modulo ULLONG_MAX+1.
Returns (unsignedlonglong)-1 on error. Use
to disambiguate.
Changed in version 3.8: Use
if available.
Changed in version 3.10: This function will no longer use
.
doublePyLong_AsDouble(
*pylong)
Part of the
.Return a C double representation of pylong. pylong must be an instance of
.
Raise
if the value of pylong is out of range for a double.
Returns -1.0 on error. Use
to disambiguate.
void*PyLong_AsVoidPtr(
*pylong)
Part of the
.Convert a Python integer pylong to a C void pointer. If pylong cannot be converted, an
will be raised. This is only assured to produce a usable void pointer for values created with
.
Returns NULL on error. Use
to disambiguate.