1
0
mirror of https://github.com/thp/pyotherside.git synced 2025-02-05 08:08:23 +08:00

Self-import pyotherside to prevent crashes

Otherwise pyotherside.QObject instances could not be used
if the same module didn't do a "import pyotherside".
This commit is contained in:
Thomas Perl 2014-10-11 18:38:06 +02:00
parent 65314f10a7
commit 78180ce840
2 changed files with 8 additions and 0 deletions

View File

@ -494,6 +494,7 @@ QPythonPriv::QPythonPriv()
, atexit_callback()
, image_provider()
, traceback_mod()
, pyotherside_mod()
, thread_state(NULL)
{
PyImport_AppendInittab("pyotherside", PyOtherSide_init);
@ -517,6 +518,12 @@ QPythonPriv::QPythonPriv()
PyEval_GetBuiltins());
}
// Need to "self-import" the pyotherside module here, so that Python code
// can use objects wrapped with pyotherside.QObject without crashing when
// the user's Python code doesn't "import pyotherside"
pyotherside_mod = PyObjectRef(PyImport_ImportModule("pyotherside"), true);
assert(pyotherside_mod);
// Release the GIL
thread_state = PyEval_SaveThread();
}

View File

@ -52,6 +52,7 @@ class QPythonPriv : public QObject {
PyObjectRef atexit_callback;
PyObjectRef image_provider;
PyObjectRef traceback_mod;
PyObjectRef pyotherside_mod;
PyThreadState *thread_state;
signals: