[Lldb-commits] [PATCH] D56511: [Python] Update PyString_FromString() to work for python 2 and 3.

Davide Italiano via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 9 13:22:12 PST 2019


davide created this revision.
davide added reviewers: aprantl, JDevlieghere, friss, zturner.

https://reviews.llvm.org/D56511

Files:
  lldb/scripts/Python/python-swigsafecast.swig
  lldb/scripts/Python/python-wrapper.swig


Index: lldb/scripts/Python/python-wrapper.swig
===================================================================
--- lldb/scripts/Python/python-wrapper.swig
+++ lldb/scripts/Python/python-wrapper.swig
@@ -826,7 +826,12 @@
     lldb::SBFrame frame_sb(frame_sp);
     PyObject *arg = SBTypeToSWIGWrapper(frame_sb);
 
-    PyObject* result = PyObject_CallMethodObjArgs(implementor, PyString_FromString(callee_name), arg, NULL);
+#if PY_MAJOR_VERSION >= 3
+    PyObject *str_arg = PyUnicode_FromString(callee_name);
+#else
+    PyObject *str_arg = PyString_FromString(callee_name);
+#endif
+    PyObject* result = PyObject_CallMethodObjArgs(implementor, str_arg, arg, NULL);
     return result;
 }
 
Index: lldb/scripts/Python/python-swigsafecast.swig
===================================================================
--- lldb/scripts/Python/python-swigsafecast.swig
+++ lldb/scripts/Python/python-swigsafecast.swig
@@ -30,7 +30,11 @@
 SBTypeToSWIGWrapper (const char* c_str)
 {
     if (c_str)
+#if PY_MAJOR_VERSION >= 3
+        return PyUnicode_FromString(c_str);
+#else
         return PyString_FromString(c_str);
+#endif
     return NULL;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56511.180912.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190109/d2bfb7c1/attachment.bin>


More information about the lldb-commits mailing list