-
Couldn't load subscription status.
- Fork 15k
[lldb] Do not narrow GetIndexOfChildWithName return type to int
#165453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modify the python wrapper to return uint32_t, which prevents incorrect child name-to-index mapping and avoids performing redundant operations on non-existent SBValues.
|
@llvm/pr-subscribers-lldb Author: Ebuka Ezike (da-viper) ChangesModify the python wrapper to return uint32_t, Full diff: https://github.com/llvm/llvm-project/pull/165453.diff 6 Files Affected:
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 64b7dc8381073..e7acba5b95d89 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -312,7 +312,7 @@ PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(PyObj
return result.release();
}
-int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
+uint32_t lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
PyObject * implementor, const char *child_name) {
PyErr_Cleaner py_err_cleaner(true);
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 6c0054a1ec1d1..edb80dc66aca7 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -352,7 +352,7 @@ class ScriptInterpreter : public PluginInterface {
return lldb::ValueObjectSP();
}
- virtual llvm::Expected<int>
+ virtual llvm::Expected<uint32_t>
GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
const char *child_name) {
return llvm::createStringError("Type has no child named '%s'", child_name);
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index 7b39d29ba2b20..27f5d2ee471c0 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -158,8 +158,9 @@ class SWIGBridge {
static PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor,
uint32_t idx);
- static int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
- const char *child_name);
+ static uint32_t
+ LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
+ const char *child_name);
static lldb::ValueObjectSP
LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data);
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 73c5c72932ff1..d257a08a2c62c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1939,7 +1939,7 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex(
return ret_val;
}
-llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
+llvm::Expected<uint32_t> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
const StructuredData::ObjectSP &implementor_sp, const char *child_name) {
if (!implementor_sp)
return llvm::createStringError("Type has no child named '%s'", child_name);
@@ -1951,7 +1951,7 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
if (!implementor)
return llvm::createStringError("Type has no child named '%s'", child_name);
- int ret_val = INT32_MAX;
+ uint32_t ret_val = UINT32_MAX;
{
Locker py_lock(this,
@@ -1960,7 +1960,7 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
child_name);
}
- if (ret_val == INT32_MAX)
+ if (ret_val == UINT32_MAX)
return llvm::createStringError("Type has no child named '%s'", child_name);
return ret_val;
}
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index dedac280788f4..00ae59c1c4241 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -122,7 +122,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
GetChildAtIndex(const StructuredData::ObjectSP &implementor,
uint32_t idx) override;
- llvm::Expected<int>
+ llvm::Expected<uint32_t>
GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
const char *child_name) override;
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
index 6f5d9fd97ee28..3d0e2d8a62482 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -90,7 +90,8 @@ PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(
return nullptr;
}
-int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
+uint32_t
+lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
PyObject *implementor, const char *child_name) {
return 0;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exported API (SBValue::GetIndexOfChildWithName) returns a uint32_t so it doesn't make any sense to use signed values in the intermediate steps.
You mentioned some kinds of bad behavior as a result of doing that. Is any of that testable? Otherwise, LGTM.
Could not find a reliable way to test it from the python API. It casts the number back to uint32_t and that is implementation defined. |
Modify the python wrapper to return uint32_t,
which prevents incorrect child name-to-index mapping and avoids performing redundant operations on non-existent SBValues.