Skip to content

Commit 8946a2d

Browse files
JDevliegheregithub-actions[bot]
authored andcommitted
Automerge: [lldb] Enforce Py_LIMITED_API in the SWIG typemaps (#168147)
We missed a handful of uses of the Python private API in the SWIG typemaps because they are included before we include the Python header that defines Py_LIMITED_API. This fixes that and guards the last private use on whether or not you're targeting the limited API. Unfortunately there doesn't appear to be an alternative, so we have to resort to being slightly less defensive.
2 parents 7f9b4fc + 94c384c commit 8946a2d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lldb/bindings/python/python-wrapper.swig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallTypeScript(
128128

129129
PyObject *pfunc_impl = nullptr;
130130

131-
if (pyfunct_wrapper && *pyfunct_wrapper &&
132-
PyFunction_Check(*pyfunct_wrapper)) {
131+
if (pyfunct_wrapper && *pyfunct_wrapper
132+
#ifndef Py_LIMITED_API
133+
&& PyFunction_Check(*pyfunct_wrapper)
134+
#endif
135+
) {
133136
pfunc_impl = (PyObject *)(*pyfunct_wrapper);
134137
if (pfunc_impl->ob_refcnt == 1) {
135138
Py_XDECREF(pfunc_impl);

lldb/bindings/python/python.swig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ except ImportError:
5959
// Parameter types will be used in the autodoc string.
6060
%feature("autodoc", "1");
6161

62+
// Include lldb-python first as it sets Py_LIMITED_API.
63+
%begin %{
64+
#include "../source/Plugins/ScriptInterpreter/Python/lldb-python.h"
65+
%}
66+
6267
%pythoncode%{
6368
import uuid
6469
import re

0 commit comments

Comments
 (0)