diff options
| author | 2010-07-04 01:11:51 +0000 | |
|---|---|---|
| committer | 2010-07-04 01:11:51 +0000 | |
| commit | 3e3780bf3eac0a4d7d9cebb9ad51a158bc5dfa20 (patch) | |
| tree | a60f588c91ed3c6c03eba41ae47895b6e287257f /src/modules/pythoncore/kvircmodule.cpp | |
| parent | Improve a bit the python interpreter: allow for passing arguments in python.b... (diff) | |
| download | KVIrc-3e3780bf3eac0a4d7d9cebb9ad51a158bc5dfa20.tar.gz KVIrc-3e3780bf3eac0a4d7d9cebb9ad51a158bc5dfa20.tar.bz2 KVIrc-3e3780bf3eac0a4d7d9cebb9ad51a158bc5dfa20.zip | |
Avoid crashing when python scripts attempt to call kvirc functions from different threads. Fixes #832
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4589 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/pythoncore/kvircmodule.cpp')
| -rw-r--r-- | src/modules/pythoncore/kvircmodule.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/modules/pythoncore/kvircmodule.cpp b/src/modules/pythoncore/kvircmodule.cpp index c662ebd1d..3bc3bf73f 100644 --- a/src/modules/pythoncore/kvircmodule.cpp +++ b/src/modules/pythoncore/kvircmodule.cpp @@ -31,11 +31,13 @@ #define KVIRC_MODULE #include "kvircmodule.h" +#include "kvi_app.h" #include "kvi_window.h" #include "kvi_userinput.h" #include "kvi_kvs_runtimecontext.h" #include "kvi_kvs_script.h" +#include <QThread> extern KviKvsRunTimeContext * g_pCurrentKvsContext; extern bool g_bExecuteQuiet; @@ -51,6 +53,12 @@ static PyObject * PyKVIrc_echo(PyObject * pSelf, PyObject * pArgs) const char * pcWinId=0; KviWindow * pWnd=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s|is",&pcText,&iColorSet,&pcWinId)) return 0; @@ -86,6 +94,12 @@ static PyObject * PyKVIrc_say(PyObject * pSelf, PyObject * pArgs) const char * pcWinId=0; KviWindow * pWnd=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s|s",&pcText,&pcWinId)) return 0; @@ -121,6 +135,12 @@ static PyObject * PyKVIrc_warning(PyObject * pSelf, PyObject * pArgs) Q_UNUSED(pSelf); const char * pcText=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s",&pcText)) return 0; @@ -139,6 +159,14 @@ static PyObject * PyKVIrc_getLocal(PyObject * pSelf, PyObject * pArgs) QString tmp; const char * szVarName=0; + + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + + if(!PyArg_ParseTuple(pArgs,"s",&szVarName)) return 0; @@ -162,6 +190,12 @@ static PyObject * PyKVIrc_setLocal(PyObject * pSelf, PyObject * pArgs) const char * szVarName=0; const char * szVarValue=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"ss",&szVarName, &szVarValue)) return 0; @@ -185,6 +219,13 @@ static PyObject * PyKVIrc_getGlobal(PyObject * pSelf, PyObject * pArgs) QString tmp; const char * szVarName=0; + + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s",&szVarName)) return 0; @@ -208,6 +249,13 @@ static PyObject * PyKVIrc_setGlobal(PyObject * pSelf, PyObject * pArgs) const char * szVarName=0; const char * szVarValue=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + + if(!PyArg_ParseTuple(pArgs,"ss",&szVarName, &szVarValue)) return 0; @@ -232,6 +280,12 @@ static PyObject * PyKVIrc_eval(PyObject * pSelf, PyObject * pArgs) char * pcRetVal=0; KviWindow * pWnd=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s",&pcCode)) return 0; @@ -265,6 +319,12 @@ static PyObject * PyKVIrc_internalWarning(PyObject * pSelf, PyObject * pArgs) Q_UNUSED(pSelf); const char * pcText=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s",&pcText)) return 0; @@ -281,6 +341,12 @@ static PyObject * PyKVIrc_error(PyObject * pSelf, PyObject * pArgs) Q_UNUSED(pSelf); const char * pcText=0; + if(QThread::currentThread() != g_pApp->thread()) + { + qDebug("[pythoncore][ERROR] kvirc module functions must be called from the main KVIrc thread"); + return 0; // Sorry, we're NOT thread safe + } + if(!PyArg_ParseTuple(pArgs,"s",&pcText)) return 0; |
