| 1 | #ifndef Py_LONGOBJECT_H |
| 2 | #define Py_LONGOBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
| 7 | |
| 8 | /* Long (arbitrary precision) integer object interface */ |
| 9 | |
| 10 | // PyLong_Type is declared by object.h |
| 11 | |
| 12 | #define PyLong_Check(op) \ |
| 13 | PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) |
| 14 | #define PyLong_CheckExact(op) Py_IS_TYPE((op), &PyLong_Type) |
| 15 | |
| 16 | PyAPI_FUNC(PyObject *) PyLong_FromLong(long); |
| 17 | PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long); |
| 18 | PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t); |
| 19 | PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t); |
| 20 | PyAPI_FUNC(PyObject *) PyLong_FromDouble(double); |
| 21 | PyAPI_FUNC(long) PyLong_AsLong(PyObject *); |
| 22 | PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *); |
| 23 | PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *); |
| 24 | PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *); |
| 25 | PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *); |
| 26 | PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *); |
| 27 | PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); |
| 28 | |
| 29 | /* It may be useful in the future. I've added it in the PyInt -> PyLong |
| 30 | cleanup to keep the extra information. [CH] */ |
| 31 | #define PyLong_AS_LONG(op) PyLong_AsLong(op) |
| 32 | |
| 33 | /* Issue #1983: pid_t can be longer than a C long on some systems */ |
| 34 | #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT |
| 35 | #define _Py_PARSE_PID "i" |
| 36 | #define PyLong_FromPid PyLong_FromLong |
| 37 | # ifndef Py_LIMITED_API |
| 38 | # define PyLong_AsPid _PyLong_AsInt |
| 39 | # elif SIZEOF_INT == SIZEOF_LONG |
| 40 | # define PyLong_AsPid PyLong_AsLong |
| 41 | # else |
| 42 | static inline int |
| 43 | PyLong_AsPid(PyObject *obj) |
| 44 | { |
| 45 | int overflow; |
| 46 | long result = PyLong_AsLongAndOverflow(obj, &overflow); |
| 47 | if (overflow || result > INT_MAX || result < INT_MIN) { |
| 48 | PyErr_SetString(PyExc_OverflowError, |
| 49 | "Python int too large to convert to C int" ); |
| 50 | return -1; |
| 51 | } |
| 52 | return (int)result; |
| 53 | } |
| 54 | # endif |
| 55 | #elif SIZEOF_PID_T == SIZEOF_LONG |
| 56 | #define _Py_PARSE_PID "l" |
| 57 | #define PyLong_FromPid PyLong_FromLong |
| 58 | #define PyLong_AsPid PyLong_AsLong |
| 59 | #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG |
| 60 | #define _Py_PARSE_PID "L" |
| 61 | #define PyLong_FromPid PyLong_FromLongLong |
| 62 | #define PyLong_AsPid PyLong_AsLongLong |
| 63 | #else |
| 64 | #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)" |
| 65 | #endif /* SIZEOF_PID_T */ |
| 66 | |
| 67 | #if SIZEOF_VOID_P == SIZEOF_INT |
| 68 | # define _Py_PARSE_INTPTR "i" |
| 69 | # define _Py_PARSE_UINTPTR "I" |
| 70 | #elif SIZEOF_VOID_P == SIZEOF_LONG |
| 71 | # define _Py_PARSE_INTPTR "l" |
| 72 | # define _Py_PARSE_UINTPTR "k" |
| 73 | #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG |
| 74 | # define _Py_PARSE_INTPTR "L" |
| 75 | # define _Py_PARSE_UINTPTR "K" |
| 76 | #else |
| 77 | # error "void* different in size from int, long and long long" |
| 78 | #endif /* SIZEOF_VOID_P */ |
| 79 | |
| 80 | PyAPI_FUNC(double) PyLong_AsDouble(PyObject *); |
| 81 | PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *); |
| 82 | PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *); |
| 83 | |
| 84 | PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long); |
| 85 | PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long); |
| 86 | PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *); |
| 87 | PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *); |
| 88 | PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *); |
| 89 | PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *); |
| 90 | |
| 91 | PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int); |
| 92 | |
| 93 | /* These aren't really part of the int object, but they're handy. The |
| 94 | functions are in Python/mystrtoul.c. |
| 95 | */ |
| 96 | PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int); |
| 97 | PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int); |
| 98 | |
| 99 | #ifndef Py_LIMITED_API |
| 100 | # define Py_CPYTHON_LONGOBJECT_H |
| 101 | # include "cpython/longobject.h" |
| 102 | # undef Py_CPYTHON_LONGOBJECT_H |
| 103 | #endif |
| 104 | |
| 105 | #ifdef __cplusplus |
| 106 | } |
| 107 | #endif |
| 108 | #endif /* !Py_LONGOBJECT_H */ |
| 109 | |