Skip to content

Commit 169d7d8

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 769c1ef commit 169d7d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,13 +634,10 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
634634
}
635635
}
636636

637+
#if SWIG_VERSION < 0x040100
637638
// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
638639
// and fixed so they will not crash if PyObject_GetBuffer fails.
639640
// 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.
643-
644641
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
645642
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
646643
int res;
@@ -674,6 +671,9 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
674671
$2 = ($2_ltype)(size / sizeof($*1_type));
675672
}
676673
%enddef
674+
#else
675+
%include <pybuffer.i>
676+
#endif
677677

678678
%pybuffer_binary(const uint8_t *buf, size_t num_bytes);
679679
%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes);

0 commit comments

Comments
 (0)