cbiesinger created this revision.
cbiesinger added a reviewer: clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In Python 3, PyInt doesn't exist (all integers are PyLongs). This patch
makes LLVM not use PyInt when compiling for Python 3. (Some code already
had such #ifs)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64373

Files:
  lldb/scripts/Python/python-swigsafecast.swig
  lldb/scripts/Python/python-typemaps.swig
  lldb/tools/intel-features/scripts/python-typemaps.txt

Index: lldb/tools/intel-features/scripts/python-typemaps.txt
===================================================================
--- lldb/tools/intel-features/scripts/python-typemaps.txt
+++ 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");
Index: lldb/scripts/Python/python-typemaps.swig
===================================================================
--- lldb/scripts/Python/python-typemaps.swig
+++ 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 <class T>
 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<T>(PyInt_AsLong(obj));
-  else if (PyLong_Check(obj))
+  else
+#endif
+  if (PyLong_Check(obj))
     number = PyLongAsT<T>(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)
         {
Index: lldb/scripts/Python/python-swigsafecast.swig
===================================================================
--- lldb/scripts/Python/python-swigsafecast.swig
+++ 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 <>
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to