diff options
Diffstat (limited to 'Include/longobject.h')
-rw-r--r-- | Include/longobject.h | 19 |
1 files changed, 18 insertions, 1 deletions
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 |