aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2021-11-18 21:27:27 +0100
committerPavel Labath <pavel@labath.sk>2021-11-22 15:14:52 +0100
commit7f09ab08de5ae8f8bd77f5c02c70b991277eb1ae (patch)
treec752360abd54d87a033778e476a8e1f917fa3ffb /lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
parent7c8ae65f2c3d5c1a6aba2f7ee7588f9f76f94f84 (diff)
downloadllvm-7f09ab08de5ae8f8bd77f5c02c70b991277eb1ae.zip
llvm-7f09ab08de5ae8f8bd77f5c02c70b991277eb1ae.tar.gz
llvm-7f09ab08de5ae8f8bd77f5c02c70b991277eb1ae.tar.bz2
[lldb] Fix [some] leaks in python bindings
Using an lldb_private object in the bindings involves three steps - wrapping the object in it's lldb::SB variant - using swig to convert/wrap that to a PyObject - wrapping *that* in a lldb_private::python::PythonObject Our SBTypeToSWIGWrapper was only handling the middle part. This doesn't just result in increased boilerplate in the callers, but is also a functionality problem, as it's very hard to get the lifetime of of all of these objects right. Most of the callers are creating the SB object (step 1) on the stack, which means that we end up with dangling python objects after the function terminates. Most of the time this isn't a problem, because the python code does not need to persist the objects. However, there are legitimate cases where they can do it (and even if the use case is not completely legitimate, crashing is not the best response to that). For this reason, some of our code creates the SB object on the heap, but it has another problem -- it never gets cleaned up. This patch begins to add a new function (ToSWIGWrapper), which does all of the three steps, while properly taking care of ownership. In the first step, I have converted most of the leaky code (except for SBStructuredData, which needs a bit more work). Differential Revision: https://reviews.llvm.org/D114259
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index 7a4b632..230fcf7 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -129,7 +129,7 @@ extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor,
extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver(
const char *python_class_name, const char *session_dictionary_name,
- lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) {
+ lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp) {
return nullptr;
}
@@ -248,7 +248,7 @@ LLDBSwigPython_GetRecognizedArguments(void *implementor,
extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(
const char *python_function_name, const char *session_dictionary_name,
- lldb::ProcessSP &process, std::string &output) {
+ const lldb::ProcessSP &process, std::string &output) {
return false;
}
@@ -260,7 +260,7 @@ extern "C" bool LLDBSWIGPythonRunScriptKeywordThread(
extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(
const char *python_function_name, const char *session_dictionary_name,
- lldb::TargetSP &target, std::string &output) {
+ const lldb::TargetSP &target, std::string &output) {
return false;
}
@@ -272,7 +272,7 @@ extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame(
extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(
const char *python_function_name, const char *session_dictionary_name,
- lldb::ValueObjectSP &value, std::string &output) {
+ const lldb::ValueObjectSP &value, std::string &output) {
return false;
}