Skip to content

Commit 506bbda

Browse files
v-einhoffstadt
authored andcommitted
fix: A regression caused by earlier optimization of list conversions.
As a side effect, reorder_items and get_values can now throw an exception if one of the tags passed in does not exist (earlier they would silently skip it).
1 parent d750f78 commit 506bbda

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

src/mvItemRegistry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ AddItemWithRuntimeChecks(mvItemRegistry& registry, std::shared_ptr<mvAppItem> it
776776
mvAppItem* beforeItem = GetItem(registry, before);
777777
if (beforeItem == nullptr)
778778
{
779-
mvThrowPythonError(mvErrorCode::mvItemNotFound, "add_*", "Item not found: " + std::to_string(parent), nullptr);
779+
mvThrowPythonError(mvErrorCode::mvItemNotFound, "add_*", "Item not found: " + std::to_string(before), nullptr);
780780
IM_ASSERT(false && "The 'before' item could not be found.");
781781
return false;
782782
}

src/mvPyUtils.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ ToUCharVect(PyObject* value, const std::string& message)
11071107
auto size = VecReserveForTuple(value, items);
11081108
for (Py_ssize_t i = 0; i < size; ++i)
11091109
{
1110-
items[i] = (unsigned char)PyLong_AsLong(PyTuple_GetItem(value, i));
1110+
items.emplace_back((unsigned char)PyLong_AsLong(PyTuple_GetItem(value, i)));
11111111
}
11121112
}
11131113

@@ -1116,7 +1116,7 @@ ToUCharVect(PyObject* value, const std::string& message)
11161116
auto size = VecReserveForList(value, items);
11171117
for (Py_ssize_t i = 0; i < size; ++i)
11181118
{
1119-
items[i] = (unsigned char)PyLong_AsLong(PyList_GetItem(value, i));
1119+
items.emplace_back((unsigned char)PyLong_AsLong(PyList_GetItem(value, i)));
11201120
}
11211121
}
11221122

@@ -1160,7 +1160,7 @@ ToIntVect(PyObject* value, const std::string& message)
11601160
auto size = VecReserveForTuple(value, items);
11611161
for (Py_ssize_t i = 0; i < size; ++i)
11621162
{
1163-
items[i] = PyLong_AsLong(PyTuple_GetItem(value, i));
1163+
items.emplace_back(PyLong_AsLong(PyTuple_GetItem(value, i)));
11641164
}
11651165
}
11661166

@@ -1169,7 +1169,7 @@ ToIntVect(PyObject* value, const std::string& message)
11691169
auto size = VecReserveForList(value, items);
11701170
for (Py_ssize_t i = 0; i < size; ++i)
11711171
{
1172-
items[i] = PyLong_AsLong(PyList_GetItem(value, i));
1172+
items.emplace_back(PyLong_AsLong(PyList_GetItem(value, i)));
11731173
}
11741174
}
11751175

@@ -1214,11 +1214,7 @@ ToUUIDVect(PyObject* value, const std::string& message)
12141214
auto size = VecReserveForTuple(value, items);
12151215
for (Py_ssize_t i = 0; i < size; ++i)
12161216
{
1217-
PyObject* item = PyTuple_GetItem(value, i);
1218-
if (isPyObject_Int(item))
1219-
items[i] = PyLong_AsUnsignedLongLong(item);
1220-
else if (isPyObject_String(item))
1221-
items[i] = GetIdFromAlias(*GContext->itemRegistry, ToString(item));
1217+
items.emplace_back(ToUUID(PyTuple_GetItem(value, i)));
12221218
}
12231219
}
12241220

@@ -1227,11 +1223,7 @@ ToUUIDVect(PyObject* value, const std::string& message)
12271223
auto size = VecReserveForList(value, items);
12281224
for (Py_ssize_t i = 0; i < size; ++i)
12291225
{
1230-
PyObject* item = PyList_GetItem(value, i);
1231-
if (isPyObject_Int(item))
1232-
items[i] = PyLong_AsUnsignedLongLong(item);
1233-
else if (isPyObject_String(item))
1234-
items[i] = GetIdFromAlias(*GContext->itemRegistry, ToString(item));
1226+
items.emplace_back(ToUUID(PyList_GetItem(value, i)));
12351227
}
12361228
}
12371229

0 commit comments

Comments
 (0)