1993-07-28 06:05:47 -03:00
|
|
|
#ifndef Py_LONGOBJECT_H
|
|
|
|
#define Py_LONGOBJECT_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1991-05-05 17:09:44 -03:00
|
|
|
|
|
|
|
/* Long (arbitrary precision) integer object interface */
|
|
|
|
|
2023-12-03 07:16:31 -04:00
|
|
|
// PyLong_Type is declared by object.h
|
1991-05-05 17:09:44 -03:00
|
|
|
|
2007-02-25 16:39:11 -04:00
|
|
|
#define PyLong_Check(op) \
|
2011-09-28 18:58:57 -03:00
|
|
|
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
|
2022-06-16 08:49:43 -03:00
|
|
|
#define PyLong_CheckExact(op) Py_IS_TYPE((op), &PyLong_Type)
|
1991-05-05 17:09:44 -03:00
|
|
|
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
|
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
|
2007-01-13 23:31:43 -04:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
|
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
|
2023-08-24 18:55:30 -03:00
|
|
|
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
|
2007-12-04 18:10:37 -04:00
|
|
|
PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
|
2007-02-27 02:57:32 -04:00
|
|
|
PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
|
2007-01-13 23:31:43 -04:00
|
|
|
PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
|
2003-04-17 15:55:45 -03:00
|
|
|
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
|
2023-08-24 18:55:30 -03:00
|
|
|
|
|
|
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
|
|
|
|
PyAPI_FUNC(int) PyLong_AsInt(PyObject *);
|
|
|
|
#endif
|
|
|
|
|
2024-08-28 07:16:13 -03:00
|
|
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030e0000
|
|
|
|
PyAPI_FUNC(PyObject*) PyLong_FromInt32(int32_t value);
|
|
|
|
PyAPI_FUNC(PyObject*) PyLong_FromUInt32(uint32_t value);
|
|
|
|
PyAPI_FUNC(PyObject*) PyLong_FromInt64(int64_t value);
|
|
|
|
PyAPI_FUNC(PyObject*) PyLong_FromUInt64(uint64_t value);
|
|
|
|
|
|
|
|
PyAPI_FUNC(int) PyLong_AsInt32(PyObject *obj, int32_t *value);
|
|
|
|
PyAPI_FUNC(int) PyLong_AsUInt32(PyObject *obj, uint32_t *value);
|
|
|
|
PyAPI_FUNC(int) PyLong_AsInt64(PyObject *obj, int64_t *value);
|
|
|
|
PyAPI_FUNC(int) PyLong_AsUInt64(PyObject *obj, uint64_t *value);
|
|
|
|
#endif
|
|
|
|
|
2009-03-18 17:06:12 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
|
2001-09-03 23:50:49 -03:00
|
|
|
|
2007-12-02 10:31:20 -04:00
|
|
|
/* It may be useful in the future. I've added it in the PyInt -> PyLong
|
|
|
|
cleanup to keep the extra information. [CH] */
|
|
|
|
#define PyLong_AS_LONG(op) PyLong_AsLong(op)
|
|
|
|
|
2010-03-14 03:49:55 -03:00
|
|
|
/* Issue #1983: pid_t can be longer than a C long on some systems */
|
|
|
|
#if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
|
2010-03-14 15:56:11 -03:00
|
|
|
#define _Py_PARSE_PID "i"
|
2010-03-14 03:49:55 -03:00
|
|
|
#define PyLong_FromPid PyLong_FromLong
|
2024-03-20 10:39:53 -03:00
|
|
|
# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
|
|
|
|
# define PyLong_AsPid PyLong_AsInt
|
|
|
|
# elif SIZEOF_INT == SIZEOF_LONG
|
|
|
|
# define PyLong_AsPid PyLong_AsLong
|
|
|
|
# else
|
|
|
|
static inline int
|
|
|
|
PyLong_AsPid(PyObject *obj)
|
|
|
|
{
|
|
|
|
int overflow;
|
|
|
|
long result = PyLong_AsLongAndOverflow(obj, &overflow);
|
|
|
|
if (overflow || result > INT_MAX || result < INT_MIN) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"Python int too large to convert to C int");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (int)result;
|
|
|
|
}
|
|
|
|
# endif
|
2010-03-14 03:49:55 -03:00
|
|
|
#elif SIZEOF_PID_T == SIZEOF_LONG
|
2010-03-14 15:56:11 -03:00
|
|
|
#define _Py_PARSE_PID "l"
|
2010-03-14 03:49:55 -03:00
|
|
|
#define PyLong_FromPid PyLong_FromLong
|
|
|
|
#define PyLong_AsPid PyLong_AsLong
|
|
|
|
#elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
|
2010-03-14 15:56:11 -03:00
|
|
|
#define _Py_PARSE_PID "L"
|
2010-03-14 03:49:55 -03:00
|
|
|
#define PyLong_FromPid PyLong_FromLongLong
|
|
|
|
#define PyLong_AsPid PyLong_AsLongLong
|
|
|
|
#else
|
|
|
|
#error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
|
|
|
|
#endif /* SIZEOF_PID_T */
|
|
|
|
|
2013-06-05 19:29:30 -03:00
|
|
|
#if SIZEOF_VOID_P == SIZEOF_INT
|
|
|
|
# define _Py_PARSE_INTPTR "i"
|
|
|
|
# define _Py_PARSE_UINTPTR "I"
|
|
|
|
#elif SIZEOF_VOID_P == SIZEOF_LONG
|
|
|
|
# define _Py_PARSE_INTPTR "l"
|
|
|
|
# define _Py_PARSE_UINTPTR "k"
|
|
|
|
#elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
|
|
|
|
# define _Py_PARSE_INTPTR "L"
|
|
|
|
# define _Py_PARSE_UINTPTR "K"
|
|
|
|
#else
|
|
|
|
# error "void* different in size from int, long and long long"
|
|
|
|
#endif /* SIZEOF_VOID_P */
|
|
|
|
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
|
|
|
|
PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
|
1992-01-19 12:31:28 -04:00
|
|
|
|
2016-09-06 14:46:49 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
|
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
|
|
|
|
PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
|
|
|
|
PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
|
|
|
|
PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
|
|
|
|
PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
|
1998-08-04 19:46:29 -03:00
|
|
|
|
2013-10-19 15:03:34 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
|
2008-05-30 15:10:19 -03:00
|
|
|
|
2013-08-27 13:40:23 -03:00
|
|
|
/* These aren't really part of the int object, but they're handy. The
|
2007-12-02 12:52:32 -04:00
|
|
|
functions are in Python/mystrtoul.c.
|
|
|
|
*/
|
2013-10-19 15:03:34 -03:00
|
|
|
PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
|
|
|
|
PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
|
2007-12-02 12:52:32 -04:00
|
|
|
|
2016-09-11 05:03:14 -03:00
|
|
|
#ifndef Py_LIMITED_API
|
2021-10-18 21:04:52 -03:00
|
|
|
# define Py_CPYTHON_LONGOBJECT_H
|
|
|
|
# include "cpython/longobject.h"
|
|
|
|
# undef Py_CPYTHON_LONGOBJECT_H
|
2017-03-30 03:09:41 -03:00
|
|
|
#endif
|
|
|
|
|
1993-07-28 06:05:47 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_LONGOBJECT_H */
|