Skip to content

Commit

Permalink
Work on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorgelmh committed Sep 13, 2024
1 parent fa03657 commit feea9d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
1 change: 0 additions & 1 deletion pythonfmu/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Fmi2Initial(Enum):
exact = 0
approx = 1
calculated = 2
none = 3 # additional value to allow for the cases when initial: --


class Fmi2Variability(Enum):
Expand Down
2 changes: 1 addition & 1 deletion pythonfmu/pythonfmu-export/src/pythonfmu/IPyState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ namespace pythonfmu
};
}

#endif //PYTHONFMU_IPYTHONSTATE_HPP
#endif //PYTHONFMU_IPYTHONSTATE_HPP
48 changes: 25 additions & 23 deletions pythonfmu/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ PySlaveInstance::PySlaveInstance(std::string instanceName, std::string resources
handle_py_exception("[ctor] PyObject_GetAttrString", gilState);
}
int success = PyList_Insert(sys_path, 0, PyUnicode_FromString(resources_.c_str()));
PyList_Append(sys_path, PyUnicode_DecodeFSDefault(resources_.c_str()));

Py_DECREF(sys_path);
if (success != 0) {
handle_py_exception("[ctor] PyList_Insert", gilState);
Expand All @@ -169,39 +169,41 @@ void PySlaveInstance::clearLogBuffer() const
PyObject* categoryField = Py_BuildValue("s", "category");
PyObject* statusField = Py_BuildValue("s", "status");

auto size = PyList_Size(pMessages_);
for (auto i = 0; i < size; i++) {
PyObject* msg = PyList_GetItem(pMessages_, i);
if ( pMessages_ != NULL && PyList_Check(pMessages_) ) {
auto size = PyList_Size(pMessages_);
for (auto i = 0; i < size; i++) {
PyObject* msg = PyList_GetItem(pMessages_, i);

auto debugAttr = PyObject_GetAttr(msg, debugField);
auto msgAttr = PyObject_GetAttr(msg, msgField);
auto categoryAttr = PyObject_GetAttr(msg, categoryField);
auto statusAttr = PyObject_GetAttr(msg, statusField);
auto debugAttr = PyObject_GetAttr(msg, debugField);
auto msgAttr = PyObject_GetAttr(msg, msgField);
auto categoryAttr = PyObject_GetAttr(msg, categoryField);
auto statusAttr = PyObject_GetAttr(msg, statusField);

auto statusValue = static_cast<cppfmu::FMIStatus>(PyLong_AsLong(statusAttr));
auto statusValue = static_cast<cppfmu::FMIStatus>(PyLong_AsLong(statusAttr));

PyObject* msgValue = PyUnicode_AsEncodedString(msgAttr, "utf-8", nullptr);
char* msgStr = PyBytes_AsString(msgValue);
logStrBuffer.emplace_back(msgValue);
PyObject* msgValue = PyUnicode_AsEncodedString(msgAttr, "utf-8", nullptr);
char* msgStr = PyBytes_AsString(msgValue);
logStrBuffer.emplace_back(msgValue);

const char* categoryStr = "";
if (categoryAttr != Py_None) {
PyObject* categoryValue = PyUnicode_AsEncodedString(categoryAttr, "utf-8", nullptr);
categoryStr = PyBytes_AsString(categoryValue);
logStrBuffer.emplace_back(categoryValue);
}
const char* categoryStr = "";
if (categoryAttr != Py_None) {
PyObject* categoryValue = PyUnicode_AsEncodedString(categoryAttr, "utf-8", nullptr);
categoryStr = PyBytes_AsString(categoryValue);
logStrBuffer.emplace_back(categoryValue);
}

if (PyObject_IsTrue(debugAttr)) {
const_cast<cppfmu::Logger&>(logger_).DebugLog(statusValue, categoryStr, msgStr);
} else {
const_cast<cppfmu::Logger&>(logger_).Log(statusValue, categoryStr, msgStr);
if (PyObject_IsTrue(debugAttr)) {
const_cast<cppfmu::Logger&>(logger_).DebugLog(statusValue, categoryStr, msgStr);
} else {
const_cast<cppfmu::Logger&>(logger_).Log(statusValue, categoryStr, msgStr);
}
}
PyList_SetSlice(pMessages_, 0, size, nullptr);
}
Py_DECREF(debugField);
Py_DECREF(msgField);
Py_DECREF(categoryField);
Py_DECREF(statusField);
PyList_SetSlice(pMessages_, 0, size, nullptr);
}

void PySlaveInstance::initialize(PyGILState_STATE gilState)
Expand Down
1 change: 1 addition & 0 deletions pythonfmu/pythonfmu-export/src/pythonfmu/PyState.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#ifndef PYTHONFMU_PYTHONSTATE_HPP
#define PYTHONFMU_PYTHONSTATE_HPP

Expand Down

0 comments on commit feea9d4

Please sign in to comment.