Skip to content

Commit 9023901

Browse files
da-vipergithub-actions[bot]
authored andcommitted
Automerge: [lldb] Do not narrow GetIndexOfChildWithName return type to int (#165453)
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.
2 parents e35199a + d87c80b commit 9023901

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

lldb/bindings/python/python-wrapper.swig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(PyObj
312312
return result.release();
313313
}
314314

315-
int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
315+
uint32_t lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
316316
PyObject * implementor, const char *child_name) {
317317
PyErr_Cleaner py_err_cleaner(true);
318318

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class ScriptInterpreter : public PluginInterface {
352352
return lldb::ValueObjectSP();
353353
}
354354

355-
virtual llvm::Expected<int>
355+
virtual llvm::Expected<uint32_t>
356356
GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
357357
const char *child_name) {
358358
return llvm::createStringError("Type has no child named '%s'", child_name);

lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ class SWIGBridge {
158158
static PyObject *LLDBSwigPython_GetChildAtIndex(PyObject *implementor,
159159
uint32_t idx);
160160

161-
static int LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
162-
const char *child_name);
161+
static uint32_t
162+
LLDBSwigPython_GetIndexOfChildWithName(PyObject *implementor,
163+
const char *child_name);
163164

164165
static lldb::ValueObjectSP
165166
LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data);

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex(
19391939
return ret_val;
19401940
}
19411941

1942-
llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
1942+
llvm::Expected<uint32_t> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
19431943
const StructuredData::ObjectSP &implementor_sp, const char *child_name) {
19441944
if (!implementor_sp)
19451945
return llvm::createStringError("Type has no child named '%s'", child_name);
@@ -1951,7 +1951,7 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
19511951
if (!implementor)
19521952
return llvm::createStringError("Type has no child named '%s'", child_name);
19531953

1954-
int ret_val = INT32_MAX;
1954+
uint32_t ret_val = UINT32_MAX;
19551955

19561956
{
19571957
Locker py_lock(this,
@@ -1960,7 +1960,7 @@ llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
19601960
child_name);
19611961
}
19621962

1963-
if (ret_val == INT32_MAX)
1963+
if (ret_val == UINT32_MAX)
19641964
return llvm::createStringError("Type has no child named '%s'", child_name);
19651965
return ret_val;
19661966
}

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
122122
GetChildAtIndex(const StructuredData::ObjectSP &implementor,
123123
uint32_t idx) override;
124124

125-
llvm::Expected<int>
125+
llvm::Expected<uint32_t>
126126
GetIndexOfChildWithName(const StructuredData::ObjectSP &implementor,
127127
const char *child_name) override;
128128

lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ PyObject *lldb_private::python::SWIGBridge::LLDBSwigPython_GetChildAtIndex(
9090
return nullptr;
9191
}
9292

93-
int lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
93+
uint32_t
94+
lldb_private::python::SWIGBridge::LLDBSwigPython_GetIndexOfChildWithName(
9495
PyObject *implementor, const char *child_name) {
9596
return 0;
9697
}

0 commit comments

Comments
 (0)