Skip to content

Conversation

@JDevlieghere
Copy link
Member

The minimum supported SWIG version is 4.0 so there's no need for using a separate file anymore.

The minimum supported SWIG version is 4.0 so there's no need for the
workaround anymore.
@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

The minimum supported SWIG version is 4.0 so there's no need for using a separate file anymore.


Full diff: https://github.com/llvm/llvm-project/pull/167966.diff

2 Files Affected:

  • (removed) lldb/bindings/python/python-typemaps.h (-19)
  • (modified) lldb/bindings/python/python-typemaps.swig (+12-6)
diff --git a/lldb/bindings/python/python-typemaps.h b/lldb/bindings/python/python-typemaps.h
deleted file mode 100644
index 8a533e822988e..0000000000000
--- a/lldb/bindings/python/python-typemaps.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
-#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
-
-#include <Python.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 4d3a95768f2f3..3baeaa7770e6c 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -6,12 +6,6 @@ AND call SWIG_fail at the same time, because it will result in a double free.
 
 */
 
-%inline %{
-
-#include "../bindings/python/python-typemaps.h"
-
-%}
-
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -640,6 +634,18 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
 //
 // I've also moved the call to PyBuffer_Release to the end of the SWIG wrapper,
 // doing it right away is not legal according to the python buffer protocol.
+%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);
+  }
+};
+%}
 
 %define %pybuffer_mutable_binary(TYPEMAP, SIZE)
 %typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {

Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@JDevlieghere JDevlieghere merged commit 36848a3 into llvm:main Nov 13, 2025
10 of 11 checks passed
@JDevlieghere JDevlieghere deleted the move-workaround branch November 13, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants