File indexing completed on 2025-11-19 09:50:53
0001 #ifndef Py_LONGOBJECT_H
0002 #define Py_LONGOBJECT_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007
0008
0009
0010
0011
0012 #define PyLong_Check(op) \
0013 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
0014 #define PyLong_CheckExact(op) Py_IS_TYPE((op), &PyLong_Type)
0015
0016 PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
0017 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
0018 PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
0019 PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
0020 PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
0021
0022 PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
0023 PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
0024 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
0025 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
0026 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
0027 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
0028
0029 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
0030 PyAPI_FUNC(int) PyLong_AsInt(PyObject *);
0031 #endif
0032
0033 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
0034
0035
0036
0037 #define PyLong_AS_LONG(op) PyLong_AsLong(op)
0038
0039
0040 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
0041 #define _Py_PARSE_PID "i"
0042 #define PyLong_FromPid PyLong_FromLong
0043 # if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
0044 # define PyLong_AsPid PyLong_AsInt
0045 # elif SIZEOF_INT == SIZEOF_LONG
0046 # define PyLong_AsPid PyLong_AsLong
0047 # else
0048 static inline int
0049 PyLong_AsPid(PyObject *obj)
0050 {
0051 int overflow;
0052 long result = PyLong_AsLongAndOverflow(obj, &overflow);
0053 if (overflow || result > INT_MAX || result < INT_MIN) {
0054 PyErr_SetString(PyExc_OverflowError,
0055 "Python int too large to convert to C int");
0056 return -1;
0057 }
0058 return (int)result;
0059 }
0060 # endif
0061 #elif SIZEOF_PID_T == SIZEOF_LONG
0062 #define _Py_PARSE_PID "l"
0063 #define PyLong_FromPid PyLong_FromLong
0064 #define PyLong_AsPid PyLong_AsLong
0065 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
0066 #define _Py_PARSE_PID "L"
0067 #define PyLong_FromPid PyLong_FromLongLong
0068 #define PyLong_AsPid PyLong_AsLongLong
0069 #else
0070 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
0071 #endif
0072
0073 #if SIZEOF_VOID_P == SIZEOF_INT
0074 # define _Py_PARSE_INTPTR "i"
0075 # define _Py_PARSE_UINTPTR "I"
0076 #elif SIZEOF_VOID_P == SIZEOF_LONG
0077 # define _Py_PARSE_INTPTR "l"
0078 # define _Py_PARSE_UINTPTR "k"
0079 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
0080 # define _Py_PARSE_INTPTR "L"
0081 # define _Py_PARSE_UINTPTR "K"
0082 #else
0083 # error "void* different in size from int, long and long long"
0084 #endif
0085
0086 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
0087 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
0088 PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
0089
0090 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
0091 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
0092 PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
0093 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
0094 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
0095 PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
0096
0097 PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
0098
0099
0100
0101
0102 PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
0103 PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
0104
0105 #ifndef Py_LIMITED_API
0106 # define Py_CPYTHON_LONGOBJECT_H
0107 # include "cpython/longobject.h"
0108 # undef Py_CPYTHON_LONGOBJECT_H
0109 #endif
0110
0111 #ifdef __cplusplus
0112 }
0113 #endif
0114 #endif