pythonfmu3 0.3.3__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. pythonfmu3/_version.py +1 -1
  2. pythonfmu3/builder.py +96 -24
  3. pythonfmu3/fmi3slave.py +80 -40
  4. pythonfmu3/modelexchange.py +17 -2
  5. pythonfmu3/osutil.py +34 -9
  6. pythonfmu3/pythonfmu-export/CMakeLists.txt +36 -4
  7. pythonfmu3/pythonfmu-export/generate_shim.py +88 -0
  8. pythonfmu3/pythonfmu-export/src/CMakeLists.txt +41 -13
  9. pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_common.hpp +3 -0
  10. pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.cpp +20 -10
  11. pythonfmu3/pythonfmu-export/src/cppfmu/cppfmu_cs.hpp +20 -10
  12. pythonfmu3/pythonfmu-export/src/cppfmu/fmi_functions.cpp +16 -14
  13. pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.cpp +570 -570
  14. pythonfmu3/pythonfmu-export/src/pythonfmu/PySlaveInstance.hpp +30 -17
  15. pythonfmu3/pythonfmu-export/src/shim/fmi3_forwarders.cpp +612 -0
  16. pythonfmu3/pythonfmu-export/src/shim/shim_loader.cpp +157 -0
  17. pythonfmu3/pythonfmu-export/src/shim/shim_loader.hpp +29 -0
  18. pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-backend.so +0 -0
  19. pythonfmu3/resources/binaries/x86_64-linux/libpythonfmu-export.so +0 -0
  20. pythonfmu3/resources/binaries/x86_64-windows/pythonfmu-export.dll +0 -0
  21. pythonfmu3/tests/data/fmi3_host.c +31 -0
  22. pythonfmu3/tests/fmi3_ctypes_driver.py +137 -0
  23. pythonfmu3/tests/slaves/pythonslave_arraytypes.py +80 -0
  24. pythonfmu3/tests/test_builder.py +48 -2
  25. pythonfmu3/tests/test_docs.py +70 -61
  26. pythonfmu3/tests/test_integration.py +106 -0
  27. pythonfmu3/tests/test_non_python_host.py +75 -0
  28. pythonfmu3/tests/test_osutil.py +23 -0
  29. pythonfmu3/tests/test_variables.py +1 -1
  30. pythonfmu3/tests/test_wrapper_ctypes.py +61 -0
  31. pythonfmu3/variables.py +72 -47
  32. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/METADATA +61 -25
  33. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/RECORD +37 -26
  34. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/WHEEL +1 -1
  35. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/entry_points.txt +0 -0
  36. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/licenses/LICENSE +0 -0
  37. {pythonfmu3-0.3.3.dist-info → pythonfmu3-1.0.0.dist-info}/top_level.txt +0 -0
@@ -18,7 +18,8 @@ class PySlaveInstance : public cppfmu::SlaveInstance
18
18
  public:
19
19
  PySlaveInstance(std::string instanceName, std::string resources, const cppfmu::Logger& logger, bool visible, std::shared_ptr<IPyState> pyState);
20
20
 
21
- void initialize(PyGILState_STATE gilState);
21
+ // Must be called with the GIL held.
22
+ void initialize();
22
23
 
23
24
  void SetupExperiment(cppfmu::FMIBoolean toleranceDefined, cppfmu::FMIFloat64 tolerance, cppfmu::FMIFloat64 tStart, cppfmu::FMIBoolean stopTimeDefined, cppfmu::FMIFloat64 tStop) override;
24
25
  void EnterInitializationMode() override;
@@ -34,18 +35,18 @@ public:
34
35
  cppfmu::FMIFloat64& endOfStep) override;
35
36
 
36
37
  void SetFloat64(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIFloat64* value, std::size_t nValues) override;
37
- void SetInt32(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIInt32* value) override;
38
- void SetInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIInt64* value) override;
39
- void SetUInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIUInt64* value) override;
40
- void SetBoolean(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIBoolean* value) override;
41
- void SetString(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIString const* value) override;
38
+ void SetInt32(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIInt32* value, std::size_t nValues) override;
39
+ void SetInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIInt64* value, std::size_t nValues) override;
40
+ void SetUInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIUInt64* value, std::size_t nValues) override;
41
+ void SetBoolean(const cppfmu::FMIValueReference* vr, std::size_t nvr, const cppfmu::FMIBoolean* value, std::size_t nValues) override;
42
+ void SetString(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIString const* value, std::size_t nValues) override;
42
43
 
43
44
  void GetFloat64(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIFloat64* value, std::size_t nValues) const override;
44
- void GetInt32(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIInt32* value) const override;
45
- void GetInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIInt64* value) const override;
46
- void GetUInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIUInt64* value) const override;
47
- void GetBoolean(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIBoolean* value) const override;
48
- void GetString(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIString* value) const override;
45
+ void GetInt32(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIInt32* value, std::size_t nValues) const override;
46
+ void GetInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIInt64* value, std::size_t nValues) const override;
47
+ void GetUInt64(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIUInt64* value, std::size_t nValues) const override;
48
+ void GetBoolean(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIBoolean* value, std::size_t nValues) const override;
49
+ void GetString(const cppfmu::FMIValueReference* vr, std::size_t nvr, cppfmu::FMIString* value, std::size_t nValues) const override;
49
50
 
50
51
  void GetFMUstate(fmi3FMUState& State) override;
51
52
  void SetFMUstate(const fmi3FMUState& State) override;
@@ -79,7 +80,7 @@ public:
79
80
 
80
81
  private:
81
82
  std::shared_ptr<IPyState> pyState_;
82
- PyObject* pClass_;
83
+ PyObject* pClass_{};
83
84
  PyObject* pInstance_{};
84
85
  PyObject* pMessages_{};
85
86
 
@@ -91,7 +92,18 @@ private:
91
92
  mutable std::vector<PyObject*> strBuffer;
92
93
  mutable std::vector<PyObject*> logStrBuffer;
93
94
 
94
- void handle_py_exception(const std::string& what, PyGILState_STATE gilState) const;
95
+ // Formats the pending Python exception (with traceback) and throws cppfmu::FatalError.
96
+ // Must be called with the GIL held; never returns.
97
+ [[noreturn]] void handle_py_exception(const std::string& what) const;
98
+
99
+ // Helpers shared by the getters/setters. All require the GIL.
100
+ void callVoidMethod(const char* method) const;
101
+ // Takes ownership of valuesList (may be nullptr if building it failed).
102
+ void callSetter(const char* method, const cppfmu::FMIValueReference* vr, std::size_t nvr, PyObject* valuesList);
103
+ // Return new references to lists holding at least the requested number of items.
104
+ PyObject* callGetter(const char* method, const cppfmu::FMIValueReference* vr, std::size_t nvr, std::size_t nValues) const;
105
+ PyObject* callListMethod(const char* method, std::size_t expected) const;
106
+ void checkListSize(PyObject* list, std::size_t expected, const char* method) const;
95
107
 
96
108
  inline void clearStrBuffer() const
97
109
  {
@@ -113,14 +125,15 @@ private:
113
125
  }
114
126
  }
115
127
 
116
- inline void cleanPyObject() const
128
+ // Releases every Python reference held by this instance. Safe to call more than once.
129
+ inline void cleanPyObject()
117
130
  {
118
131
  clearLogBuffer();
119
132
  clearLogStrBuffer();
120
133
  clearStrBuffer();
121
- Py_XDECREF(pClass_);
122
- Py_XDECREF(pInstance_);
123
- Py_XDECREF(pMessages_);
134
+ Py_CLEAR(pClass_);
135
+ Py_CLEAR(pInstance_);
136
+ Py_CLEAR(pMessages_);
124
137
  }
125
138
  };
126
139