Maybe fixing issue #1619 (crash on Fedora-39 upon initialization) (#1622)

* Maybe fixing issue #1619 (crash on Fedora-39 upon initialization)

* Python 3.6 compatibility

---------

Co-authored-by: Matthias Koefferlein <matthias@klayout.de>
This commit is contained in:
Matthias Köfferlein 2024-02-12 08:40:39 +01:00 committed by GitHub
parent a4ab59ba6f
commit cc7622b6b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 16 deletions

View File

@ -185,7 +185,7 @@ PythonInterpreter::PythonInterpreter (bool embedded)
: gsi::Interpreter (0, "pya"),
mp_current_console (0), mp_current_exec_handler (0), m_current_exec_level (0),
m_in_trace (false), m_block_exceptions (false), m_ignore_next_exception (false),
mp_current_frame (NULL), mp_py3_app_name (0), m_embedded (embedded)
mp_current_frame (NULL), m_embedded (embedded)
{
// Don't attempt any additional initialization in the standalone module case
if (! embedded) {
@ -325,18 +325,15 @@ PythonInterpreter::PythonInterpreter (bool embedded)
#else
// Python 3 requires a unicode string for the application name
PyObject *an = c2python (app_path);
tl_assert (an != NULL);
mp_py3_app_name = PyUnicode_AsWideCharString (an, NULL);
tl_assert (mp_py3_app_name != NULL);
Py_DECREF (an);
Py_SetProgramName (mp_py3_app_name);
mp_py3_app_name = tl::to_wstring (app_path);
Py_SetProgramName (const_cast<wchar_t *> (mp_py3_app_name.c_str ()));
Py_InitializeEx (0 /*don't set signals*/);
// Set dummy argv[]
// TODO: more?
wchar_t *argv[1] = { mp_py3_app_name };
wchar_t *argv[1] = { const_cast<wchar_t *> (mp_py3_app_name.c_str()) };
PySys_SetArgvEx (1, argv, 0);
#endif
@ -371,14 +368,7 @@ PythonInterpreter::~PythonInterpreter ()
sp_interpreter = 0;
if (m_embedded) {
Py_Finalize ();
if (mp_py3_app_name) {
PyMem_Free (mp_py3_app_name);
mp_py3_app_name = 0;
}
}
}

View File

@ -277,7 +277,7 @@ private:
std::string m_debugger_scope;
PyFrameObject *mp_current_frame;
std::map<PyObject *, size_t> m_file_id_map;
wchar_t *mp_py3_app_name;
std::wstring mp_py3_app_name;
bool m_embedded;
std::unique_ptr<pya::PythonModule> m_pya_module;
};