17 #define Py_True ( (PyObject*)(void*)&_Py_TrueStruct )
21 #define Py_False ( (PyObject*)(void*)&_Py_ZeroStruct )
27 #include "GaudiKernel/System.h"
28 #include "GaudiKernel/StatusCode.h"
36 void report_py_exception (
bool display =
true)
40 PyObject* pytype =
nullptr, *pyvalue =
nullptr, *pytrace =
nullptr;
41 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
46 PyErr_Restore (pytype, pyvalue, pytrace);
62 if (Py_IsInitialized()) {
63 return StatusCode::SUCCESS;
70 #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 11
73 if (!Py_IsInitialized()) {
74 ::report_py_exception();
75 return StatusCode::FAILURE;
80 []() { std::vector<std::wstring> wargs;
84 using convert_t = std::codecvt_utf8<wchar_t>;
85 std::wstring_convert<convert_t, wchar_t> strconverter;
87 wargs.push_back (strconverter.from_bytes (
argv[
i]));
91 static const std::vector<std::wstring> wargs = wargsinit();
94 [](
const std::vector<std::wstring>& wargs)
95 { std::vector<const wchar_t*> wargv;
98 wargv.push_back (wargs[
i].
data());
102 static const std::vector<const wchar_t*> wargv = wargvinit (wargs);
109 PyConfig_InitPythonConfig (&
config);
112 if (PyStatus_Exception (
status)) {
113 report_py_exception();
115 return StatusCode::FAILURE;
119 if (PyStatus_Exception (
status)) {
120 report_py_exception();
122 return StatusCode::FAILURE;
126 return StatusCode::SUCCESS;