Skip to content

Commit 5d8eede

Browse files
committed
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
1 parent 21ad3c4 commit 5d8eede

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
2+
#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
3+
4+
// Defined here instead of a .swig file because SWIG 2 doesn't support
5+
// explicit deleted functions.
6+
struct Py_buffer_RAII {
7+
Py_buffer buffer = {};
8+
Py_buffer_RAII(){};
9+
Py_buffer &operator=(const Py_buffer_RAII &) = delete;
10+
Py_buffer_RAII(const Py_buffer_RAII &) = delete;
11+
~Py_buffer_RAII() {
12+
if (buffer.obj)
13+
PyBuffer_Release(&buffer);
14+
}
15+
};
16+
17+
#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H

lldb/bindings/python/python-typemaps.swig

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
22

3+
%inline %{
4+
5+
#include "../bindings/python/python-typemaps.h"
6+
7+
%}
8+
39
%typemap(in) char ** {
410
/* Check if is a list */
511
if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
6167

6268
%typemap(in) lldb::tid_t {
6369
PythonObject obj = Retain<PythonObject>($input);
64-
lldb::tid_t value = unwrapOrSetPythonException(As<unsigned long long>(obj));
70+
lldb::tid_t value = unwrapOrSetPythonException(As<unsigned long long>(obj));
6571
if (PyErr_Occurred())
6672
return nullptr;
6773
$1 = value;
@@ -476,21 +482,6 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
476482
}
477483
}
478484

479-
%inline %{
480-
481-
struct Py_buffer_RAII {
482-
Py_buffer buffer = {};
483-
Py_buffer_RAII() {};
484-
Py_buffer &operator=(const Py_buffer_RAII &) = delete;
485-
Py_buffer_RAII(const Py_buffer_RAII &) = delete;
486-
~Py_buffer_RAII() {
487-
if (buffer.obj)
488-
PyBuffer_Release(&buffer);
489-
}
490-
};
491-
492-
%}
493-
494485
// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
495486
// and fixed so they will not crash if PyObject_GetBuffer fails.
496487
// https://github.com/swig/swig/issues/1640

0 commit comments

Comments
 (0)