diff --git a/src/pya/pya/pya.cc b/src/pya/pya/pya.cc index d46f49ec0..8e720cc59 100644 --- a/src/pya/pya/pya.cc +++ b/src/pya/pya/pya.cc @@ -221,7 +221,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) { @@ -347,19 +347,16 @@ 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 (mp_py3_app_name.c_str ())); PyImport_AppendInittab (pya_module_name, &init_pya_module); 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 (mp_py3_app_name.c_str()) }; PySys_SetArgvEx (1, argv, 0); // Import the module @@ -396,14 +393,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; - } - } } diff --git a/src/pya/pya/pya.h b/src/pya/pya/pya.h index d0d18fce8..6a93f26fb 100644 --- a/src/pya/pya/pya.h +++ b/src/pya/pya/pya.h @@ -276,7 +276,7 @@ private: std::string m_debugger_scope; PyFrameObject *mp_current_frame; std::map m_file_id_map; - wchar_t *mp_py3_app_name; + std::wstring mp_py3_app_name; bool m_embedded; std::unique_ptr m_pya_module; };