16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 13:59:19 +02:00

Tweak python command return logic to prevent crashing simulator

This commit is contained in:
2025-01-08 16:28:50 +01:00
parent 988b3dfe1f
commit a46faf6ff9

View File

@@ -504,11 +504,11 @@ python_taskqueue::error() {
std::vector<std::string> python_external_utils::PyObjectToStringArray(PyObject *pyList) std::vector<std::string> python_external_utils::PyObjectToStringArray(PyObject *pyList)
{ {
std::vector<std::string> result; std::vector<std::string> result;
std::vector<std::string> emptyIfError = {};
if (!PySequence_Check(pyList)) if (!PySequence_Check(pyList))
{ {
ErrorLog("Provided PyObject is not a sequence."); ErrorLog("Python: Failed to convert PyObject -> vector<string>");
return result; return emptyIfError;
} }
Py_ssize_t size = PySequence_Size(pyList); Py_ssize_t size = PySequence_Size(pyList);
@@ -517,16 +517,16 @@ std::vector<std::string> python_external_utils::PyObjectToStringArray(PyObject *
PyObject *item = PySequence_GetItem(pyList, i); // Increments reference count PyObject *item = PySequence_GetItem(pyList, i); // Increments reference count
if (item == nullptr) if (item == nullptr)
{ {
ErrorLog("Failed to get item from sequence."); ErrorLog("Python: Failed to get item from sequence.");
return result; return emptyIfError;
} }
const char *str = PyString_AsString(item); const char *str = PyString_AsString(item);
if (str == nullptr) if (str == nullptr)
{ {
Py_DECREF(item); Py_DECREF(item);
ErrorLog("Failed to convert item to string."); ErrorLog("Python: Failed to convert item to string.");
return result; return emptyIfError;
} }
result.push_back(std::string(str)); result.push_back(std::string(str));