[Lldb-commits] [lldb] 5d8eede - Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

António Afonso via lldb-commits lldb-commits at lists.llvm.org
Sat Aug 22 10:44:17 PDT 2020


Author: António Afonso
Date: 2020-08-22T10:43:50-07:00
New Revision: 5d8eedee917de2d39d1c485d07a30f8649bc6866

URL: https://github.com/llvm/llvm-project/commit/5d8eedee917de2d39d1c485d07a30f8649bc6866
DIFF: https://github.com/llvm/llvm-project/commit/5d8eedee917de2d39d1c485d07a30f8649bc6866.diff

LOG: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

`struct Py_buffer_RAII` definition uses explicit deleted functions which are not supported by SWIG 2 (only 3).
To get around this I moved this struct to an .h file that is included to avoid being parsed by swig.

Reviewed By: lawrence_danna

Differential Revision: https://reviews.llvm.org/D86381

Added: 
    lldb/bindings/python/python-typemaps.h

Modified: 
    lldb/bindings/python/python-typemaps.swig

Removed: 
    


################################################################################
diff  --git a/lldb/bindings/python/python-typemaps.h b/lldb/bindings/python/python-typemaps.h
new file mode 100644
index 000000000000..b45352ad6295
--- /dev/null
+++ b/lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,17 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+    if (buffer.obj)
+      PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H

diff  --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig
index c08aeab71f78..b1ace4ff3b1e 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain<PythonObject>($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As<unsigned long long>(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As<unsigned long long>(obj));
   if (PyErr_Occurred())
     return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
     }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-    if (buffer.obj)
-      PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640


        


More information about the lldb-commits mailing list