diff --git a/lldb/scripts/Python/python-swigsafecast.swig b/lldb/scripts/Python/python-swigsafecast.swig --- a/lldb/scripts/Python/python-swigsafecast.swig +++ b/lldb/scripts/Python/python-swigsafecast.swig @@ -31,7 +31,11 @@ { if (!c_int) return NULL; +#if PY_MAJOR_VERSION < 3 return PyInt_FromLong(*c_int); +#else + return PyLong_FromLong(*c_int); +#endif } template <> diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -102,11 +102,20 @@ // typemap for a char buffer // See also SBThread::GetStopDescription. %typemap(in) (char *dst, size_t dst_len) { + // In Python 3, all integers are PyLongs +#if PY_MAJOR_VERSION < 3 if (!PyInt_Check($input)) { +#else + if (!PyLong_Check($input)) { +#endif PyErr_SetString(PyExc_ValueError, "Expecting an integer"); return NULL; } +#if PY_MAJOR_VERSION < 3 $2 = PyInt_AsLong($input); +#else + $2 = PyLong_AsLong($input); +#endif if ($2 <= 0) { PyErr_SetString(PyExc_ValueError, "Positive integer expected"); return NULL; @@ -191,9 +200,14 @@ // typemap for an incoming buffer // See also SBProcess::ReadMemory. %typemap(in) (void *buf, size_t size) { + // In Python 3, all integers are PyLongs, so the PyInt code is only needed + // on Python 2. +#if PY_MAJOR_VERSION < 3 if (PyInt_Check($input)) { $2 = PyInt_AsLong($input); - } else if (PyLong_Check($input)) { + } else +#endif + if (PyLong_Check($input)) { $2 = PyLong_AsLong($input); } else { PyErr_SetString(PyExc_ValueError, "Expecting an integer or long object"); @@ -245,9 +259,14 @@ template bool SetNumberFromPyObject(T &number, PyObject *obj) { + // In Python 3, all integers are PyLongs, so the PyInt code is only needed + // on Python 2. +#if PY_MAJOR_VERSION < 3 if (PyInt_Check(obj)) number = static_cast(PyInt_AsLong(obj)); - else if (PyLong_Check(obj)) + else +#endif + if (PyLong_Check(obj)) number = PyLongAsT(obj); else return false; @@ -333,7 +352,11 @@ PyObject* list = PyList_New(count); for (uint32_t j = 0; j < count; j++) { +#if PY_MAJOR_VERSION < 3 PyObject* item = PyInt_FromLong($1[j]); +#else + PyObject* item = PyLong_FromLong($1[j]); +#endif int ok = PyList_SetItem(list,j,item); if (ok != 0) { diff --git a/lldb/tools/intel-features/scripts/python-typemaps.txt b/lldb/tools/intel-features/scripts/python-typemaps.txt --- a/lldb/tools/intel-features/scripts/python-typemaps.txt +++ b/lldb/tools/intel-features/scripts/python-typemaps.txt @@ -2,9 +2,12 @@ // typemap for an incoming buffer %typemap(in) (void *buf, size_t size) { +#if PY_MAJOR_VERSION < 3 if (PyInt_Check($input)) { $2 = PyInt_AsLong($input); - } else if (PyLong_Check($input)) { + } else +#endif + if (PyLong_Check($input)) { $2 = PyLong_AsLong($input); } else { PyErr_SetString(PyExc_ValueError, "Expecting an integer or long object");