diff options
Diffstat (limited to 'Include')
-rw-r--r-- | Include/Python.h | 6 | ||||
-rw-r--r-- | Include/longobject.h | 19 |
2 files changed, 21 insertions, 4 deletions
diff --git a/Include/Python.h b/Include/Python.h index 52a7aac..5eddda6 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -49,6 +49,9 @@ #include "bytearrayobject.h" #include "bytesobject.h" #include "unicodeobject.h" +#include "cpython/initconfig.h" +#include "pystate.h" +#include "pyerrors.h" #include "longobject.h" #include "cpython/longintrepr.h" #include "boolobject.h" @@ -74,8 +77,6 @@ #include "sliceobject.h" #include "cpython/cellobject.h" #include "iterobject.h" -#include "cpython/initconfig.h" -#include "pystate.h" #include "cpython/genobject.h" #include "descrobject.h" #include "genericaliasobject.h" @@ -85,7 +86,6 @@ #include "cpython/picklebufobject.h" #include "cpython/pytime.h" #include "codecs.h" -#include "pyerrors.h" #include "pythread.h" #include "cpython/context.h" #include "modsupport.h" diff --git a/Include/longobject.h b/Include/longobject.h index e090dd0..c8b7497 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -34,7 +34,24 @@ PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT #define _Py_PARSE_PID "i" #define PyLong_FromPid PyLong_FromLong -#define PyLong_AsPid PyLong_AsLong +# ifndef Py_LIMITED_API +# 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 #elif SIZEOF_PID_T == SIZEOF_LONG #define _Py_PARSE_PID "l" #define PyLong_FromPid PyLong_FromLong |