Skip to content

Commit 5baef17

Browse files
committed
[lldb] Limit Py_buffer_RAII to SWIG < 4.1
The bug [1] this is working around was fixed in SWIG 4.1. The workaround uses functions and constants that are not part of the limited API, which I'm trying to eliminate to make LLDB compatible with the Python Limited C API [2]. [1] swig/swig#1640 [2] #151617
1 parent 9f0c449 commit 5baef17

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lldb/bindings/python/python-typemaps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <Python.h>
55

6+
#if SWIG_VERSION < 0x040100
67
// Defined here instead of a .swig file because SWIG 2 doesn't support
78
// explicit deleted functions.
89
struct Py_buffer_RAII {
@@ -15,5 +16,6 @@ struct Py_buffer_RAII {
1516
PyBuffer_Release(&buffer);
1617
}
1718
};
19+
#endif
1820

1921
#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H

lldb/bindings/python/python-typemaps.swig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,7 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
637637
// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
638638
// and fixed so they will not crash if PyObject_GetBuffer fails.
639639
// https://github.com/swig/swig/issues/1640
640-
//
641-
// I've also moved the call to PyBuffer_Release to the end of the SWIG wrapper,
642-
// doing it right away is not legal according to the python buffer protocol.
640+
#if SWIG_VERSION < 0x040100
643641

644642
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
645643
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
@@ -678,6 +676,8 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
678676
%pybuffer_binary(const uint8_t *buf, size_t num_bytes);
679677
%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes);
680678

679+
#endif
680+
681681
%typemap(in) (const char **symbol_name, uint32_t num_names) {
682682
using namespace lldb_private;
683683
/* Check if is a list */

0 commit comments

Comments
 (0)