diff --git a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp index fbf7ef8dc9b..baced0b15ab 100644 --- a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp +++ b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp @@ -74,14 +74,8 @@ static PyObject *cdbext_listOfLocals(PyObject *, PyObject *) // -> [ Value ] const auto children = sg->root()->children(); auto locals = PyList_New(0); for (AbstractSymbolGroupNode *abstractChild : children) { - Value *childValue = PyObject_New(Value, value_pytype()); - if (childValue != NULL) { - if (SymbolGroupNode* child = abstractChild->asSymbolGroupNode()) { - childValue->m_index = child->index(); - childValue->m_symbolGroup = sg->debugSymbolGroup(); - } - } - PyList_Append(locals, reinterpret_cast(childValue)); + if (SymbolGroupNode* child = abstractChild->asSymbolGroupNode()) + PyList_Append(locals, createValue(child->index(), sg->debugSymbolGroup())); } return locals; diff --git a/src/libs/qtcreatorcdbext/pyvalue.cpp b/src/libs/qtcreatorcdbext/pyvalue.cpp index 56f56e6a5cf..3824e70ef72 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.cpp +++ b/src/libs/qtcreatorcdbext/pyvalue.cpp @@ -125,23 +125,18 @@ PyObject *value_Dereference(Value *self) char *name = getTypeName(params.Module, params.TypeId); - Value *ret = self; + PyObject *ret = reinterpret_cast(self); if (endsWith(std::string(name), "*")) { if (numberOfChildren(self) > 0 && expandValue(self)) { ULONG symbolCount = 0; self->m_symbolGroup->GetNumberSymbols(&symbolCount); - if (symbolCount > self->m_index + 1) { - ret = PyObject_New(Value, value_pytype()); - if (ret != NULL) { - ret->m_index = self->m_index + 1; - ret->m_symbolGroup = self->m_symbolGroup; - } - } + if (symbolCount > self->m_index + 1) + ret = createValue(self->m_index + 1, self->m_symbolGroup); } } delete[] name; - return reinterpret_cast(ret); + return ret; } PyObject *value_HasChildren(Value *self) @@ -187,14 +182,8 @@ PyObject *value_ChildFromName(Value *self, PyObject *args) Py_RETURN_NONE; for (ULONG childIndex = self->m_index + 1 ; childIndex <= self->m_index + childCount; ++childIndex) { - if (getSymbolName(self->m_symbolGroup, childIndex) == name) { - Value *childValue = PyObject_New(Value, value_pytype()); - if (childValue != NULL) { - childValue->m_index = childIndex; - childValue->m_symbolGroup = self->m_symbolGroup; - } - return reinterpret_cast(childValue); - } + if (getSymbolName(self->m_symbolGroup, childIndex) == name) + return createValue(childIndex, self->m_symbolGroup); } Py_RETURN_NONE; @@ -241,12 +230,7 @@ PyObject *value_ChildFromField(Value *self, PyObject *args) if (FAILED(self->m_symbolGroup->AddSymbol(name.c_str(), &index))) Py_RETURN_NONE; - Value *childValue = PyObject_New(Value, value_pytype()); - if (childValue != NULL) { - childValue->m_index = index; - childValue->m_symbolGroup = self->m_symbolGroup; - } - return reinterpret_cast(childValue); + return createValue(index, self->m_symbolGroup); } PyObject *value_ChildFromIndex(Value *self, PyObject *args) @@ -264,13 +248,7 @@ PyObject *value_ChildFromIndex(Value *self, PyObject *args) if (childCount <= index || !expandValue(self)) Py_RETURN_NONE; - Value *childValue = PyObject_New(Value, value_pytype()); - if (childValue != NULL) { - childValue->m_index = self->m_index + index + 1; - childValue->m_symbolGroup = self->m_symbolGroup; - } - - return reinterpret_cast(childValue); + return createValue(self->m_index + index + 1, self->m_symbolGroup); } void value_Dealloc(Value *) @@ -290,6 +268,16 @@ void initValue(Value *value) value->m_symbolGroup = nullptr; } +PyObject *createValue(ULONG index, CIDebugSymbolGroup *symbolGroup) +{ + Value *value = PyObject_New(Value, value_pytype()); + if (value != NULL) { + value->m_index = index; + value->m_symbolGroup = symbolGroup; + } + return reinterpret_cast(value); +} + static PyMethodDef valueMethods[] = { {"name", PyCFunction(value_Name), METH_NOARGS, "Name of this thing or None"}, diff --git a/src/libs/qtcreatorcdbext/pyvalue.h b/src/libs/qtcreatorcdbext/pyvalue.h index 1c5c1ea0036..e7aac4e29fe 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.h +++ b/src/libs/qtcreatorcdbext/pyvalue.h @@ -40,3 +40,4 @@ struct Value PyTypeObject *value_pytype(); void initValue(Value *value); +PyObject *createValue(ULONG index, CIDebugSymbolGroup *symbolGroup);