Python: Fix --disable-shared.

This commit is contained in:
Gunnar Beutner 2013-02-16 12:36:25 +01:00
parent d0f263abb1
commit 7cb67afaae
2 changed files with 15 additions and 1 deletions

View File

@ -31,8 +31,14 @@ PyMethodDef PythonLanguage::m_NativeMethodDef[] = {
};
PythonLanguage::PythonLanguage(void)
: ScriptLanguage()
: ScriptLanguage(), m_Initialized(false)
{ }
void PythonLanguage::InitializeOnce(void)
{
if (m_Initialized)
return;
Py_Initialize();
PyEval_InitThreads();
@ -59,6 +65,8 @@ PythonLanguage::PythonLanguage(void)
ScriptFunction::OnRegistered.connect(boost::bind(&PythonLanguage::RegisterNativeFunction, this, _1, _2));
ScriptFunction::OnUnregistered.connect(boost::bind(&PythonLanguage::UnregisterNativeFunction, this, _1));
m_Initialized = true;
}
PythonLanguage::~PythonLanguage(void)
@ -70,6 +78,8 @@ PythonLanguage::~PythonLanguage(void)
ScriptInterpreter::Ptr PythonLanguage::CreateInterpreter(const Script::Ptr& script)
{
InitializeOnce();
return boost::make_shared<PythonInterpreter>(GetSelf(), script);
}

View File

@ -50,7 +50,9 @@ public:
static Value MarshalFromPython(PyObject *value);
String ExceptionInfoToString(PyObject *type, PyObject *exc, PyObject *tb) const;
private:
bool m_Initialized;
PyThreadState *m_MainThreadState;
PyObject *m_NativeModule;
PyObject *m_TracebackModule;
@ -63,6 +65,8 @@ private:
static PyObject *PyRegisterFunction(PyObject *self, PyObject *args);
static PyMethodDef m_NativeMethodDef[];
void InitializeOnce(void);
};
}