Skip to content

Commit

Permalink
Maybe fixing issue #1619 (crash on Fedora-39 upon initialization) (#1622
Browse files Browse the repository at this point in the history
)

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

* Python 3.6 compatibility

---------

Co-authored-by: Matthias Koefferlein <[email protected]>
  • Loading branch information
klayoutmatthias and Matthias Koefferlein authored Feb 12, 2024
1 parent a4ab59b commit cc7622b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions src/pya/pya/pya.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pya/pya/pya.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class PYA_PUBLIC PythonInterpreter
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;
};
Expand Down

0 comments on commit cc7622b

Please sign in to comment.