File indexing completed on 2025-01-18 10:06:49
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 PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
0022 PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
0023 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
0024 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
0025 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
0026 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
0027 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
0028
0029
0030
0031 #define PyLong_AS_LONG(op) PyLong_AsLong(op)
0032
0033
0034 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
0035 #define _Py_PARSE_PID "i"
0036 #define PyLong_FromPid PyLong_FromLong
0037 # ifndef Py_LIMITED_API
0038 # define PyLong_AsPid _PyLong_AsInt
0039 # elif SIZEOF_INT == SIZEOF_LONG
0040 # define PyLong_AsPid PyLong_AsLong
0041 # else
0042 static inline int
0043 PyLong_AsPid(PyObject *obj)
0044 {
0045 int overflow;
0046 long result = PyLong_AsLongAndOverflow(obj, &overflow);
0047 if (overflow || result > INT_MAX || result < INT_MIN) {
0048 PyErr_SetString(PyExc_OverflowError,
0049 "Python int too large to convert to C int");
0050 return -1;
0051 }
0052 return (int)result;
0053 }
0054 # endif
0055 #elif SIZEOF_PID_T == SIZEOF_LONG
0056 #define _Py_PARSE_PID "l"
0057 #define PyLong_FromPid PyLong_FromLong
0058 #define PyLong_AsPid PyLong_AsLong
0059 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
0060 #define _Py_PARSE_PID "L"
0061 #define PyLong_FromPid PyLong_FromLongLong
0062 #define PyLong_AsPid PyLong_AsLongLong
0063 #else
0064 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
0065 #endif
0066
0067 #if SIZEOF_VOID_P == SIZEOF_INT
0068 # define _Py_PARSE_INTPTR "i"
0069 # define _Py_PARSE_UINTPTR "I"
0070 #elif SIZEOF_VOID_P == SIZEOF_LONG
0071 # define _Py_PARSE_INTPTR "l"
0072 # define _Py_PARSE_UINTPTR "k"
0073 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
0074 # define _Py_PARSE_INTPTR "L"
0075 # define _Py_PARSE_UINTPTR "K"
0076 #else
0077 # error "void* different in size from int, long and long long"
0078 #endif
0079
0080 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
0081 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
0082 PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
0083
0084 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
0085 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
0086 PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
0087 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
0088 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
0089 PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
0090
0091 PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
0092
0093
0094
0095
0096 PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
0097 PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
0098
0099 #ifndef Py_LIMITED_API
0100 # define Py_CPYTHON_LONGOBJECT_H
0101 # include "cpython/longobject.h"
0102 # undef Py_CPYTHON_LONGOBJECT_H
0103 #endif
0104
0105 #ifdef __cplusplus
0106 }
0107 #endif
0108 #endif