aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-08-01 16:18:24 -0700
committerGitHub <noreply@github.com>2025-08-01 16:18:24 -0700
commit4d1ae58d9e1d679cd0f35ce935579df221b14882 (patch)
tree062cb99bd36fea59d03e2e177cc85fbb183c40b3 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
parent33abf05af4f8f7f80856bd018d117c98f8807e87 (diff)
downloadllvm-4d1ae58d9e1d679cd0f35ce935579df221b14882.zip
llvm-4d1ae58d9e1d679cd0f35ce935579df221b14882.tar.gz
llvm-4d1ae58d9e1d679cd0f35ce935579df221b14882.tar.bz2
[lldb] Reimplment PyRun_SimpleString using the Python stable C API (#151777)
Reimplment `PyRun_SimpleString` using the Python stable C API and the `RunString` helper. Part of https://github.com/llvm/llvm-project/issues/151617
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 9fe2824..42dc579 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1492,6 +1492,22 @@ PyObject *RunString(const char *str, int start, PyObject *globals,
return result;
}
+
+int RunSimpleString(const char *str) {
+ PyObject *main_module = PyImport_AddModule("__main__");
+ if (!main_module)
+ return -1;
+
+ PyObject *globals = PyModule_GetDict(main_module);
+ if (!globals)
+ return -1;
+
+ PyObject *result = RunString(str, Py_file_input, globals, globals);
+ if (!result)
+ return -1;
+
+ return 0;
+}
} // namespace python
} // namespace lldb_private