Commit 62e2c9b9 authored by Pino Toscano's avatar Pino Toscano

scripting: fix Python initialization

Apparently with Python 3.9 Py_Initialize() is needed even before
creating PyObject's, i.e. what the default constructor of
boost::python:dict does by calling PyDict_New().

Hence, move the insertion of the 'kig' module followed by
Py_Initialize() in the constructor of a separate helper class: this
class will be a private base for PythonScripter::Private, which thus can
properly initialize boost::python objects.
parent 8ea52197
......@@ -361,22 +361,18 @@ BOOST_PYTHON_MODULE_INIT( kig )
}
PythonScripter* PythonScripter::instance()
{
static PythonScripter t;
return &t;
}
class PythonScripter::Private
// helper class to initialize Python in a constructor;
// this way, PythonScripter::Private inherits from it and thus
// already has Python initialized before the class members
// (like 'mainnamespace') are initialized
class PythonInitializer
{
public:
dict mainnamespace;
PythonInitializer();
};
PythonScripter::PythonScripter()
PythonInitializer::PythonInitializer()
{
d = new Private;
// tell the python interpreter about our API..
PyImport_AppendInittab( "kig", PyInit_kig );
......@@ -386,6 +382,23 @@ PythonScripter::PythonScripter()
PyRun_SimpleString( "import math; from math import *;" );
PyRun_SimpleString( "import kig; from kig import *;" );
PyRun_SimpleString( "import traceback;" );
}
PythonScripter* PythonScripter::instance()
{
static PythonScripter t;
return &t;
}
class PythonScripter::Private : private PythonInitializer
{
public:
dict mainnamespace;
};
PythonScripter::PythonScripter()
{
d = new Private;
// find the main namespace..
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment