From 7cb67afaae34030da32412da10aeefe39d9ee555 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 16 Feb 2013 12:36:25 +0100 Subject: [PATCH] Python: Fix --disable-shared. --- lib/python/pythonlanguage.cpp | 12 +++++++++++- lib/python/pythonlanguage.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp index d5b832e9f..3ea81bd9b 100644 --- a/lib/python/pythonlanguage.cpp +++ b/lib/python/pythonlanguage.cpp @@ -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(GetSelf(), script); } diff --git a/lib/python/pythonlanguage.h b/lib/python/pythonlanguage.h index 099c0e47d..fc92ff2cc 100644 --- a/lib/python/pythonlanguage.h +++ b/lib/python/pythonlanguage.h @@ -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); }; }