diff options
| author | 2009-09-24 22:02:53 +0000 | |
|---|---|---|
| committer | 2009-09-24 22:02:53 +0000 | |
| commit | 7f45ba247a7cbb93f44dfb8650d5d9a86ac12301 (patch) | |
| tree | 5319dc6d970e1d91c8e2861b7b65b149d11c0cf3 /src/modules/pythoncore | |
| parent | some work on python module (diff) | |
| download | KVIrc-7f45ba247a7cbb93f44dfb8650d5d9a86ac12301.tar.gz KVIrc-7f45ba247a7cbb93f44dfb8650d5d9a86ac12301.tar.bz2 KVIrc-7f45ba247a7cbb93f44dfb8650d5d9a86ac12301.zip | |
more fixes to pytho module. now it is able to correctly run python code :)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3525 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/pythoncore')
| -rw-r--r-- | src/modules/pythoncore/libkvipythoncore.cpp | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/modules/pythoncore/libkvipythoncore.cpp b/src/modules/pythoncore/libkvipythoncore.cpp index 37fa88dc0..fd9602b9a 100644 --- a/src/modules/pythoncore/libkvipythoncore.cpp +++ b/src/modules/pythoncore/libkvipythoncore.cpp @@ -112,19 +112,51 @@ bool KviPythonInterpreter::execute( return false; } + int retVal; + // grab the global interpreter lock PyEval_AcquireLock(); // swap in my thread state PyThreadState_Swap(m_pThreadState); // execute some python code - PyRun_SimpleString("import sys\n"); - PyRun_SimpleString("sys.stdout.write('Hello from a C thread!\\n')\n"); + retVal = PyRun_SimpleString(szCode.toUtf8().data()); + + szRetVal.setNum(retVal); + + if (PyErr_Occurred()) + { + // PyErr_Print(); + PyObject *type = NULL, *value = NULL, *traceback = NULL, *pyString = NULL; + PyErr_Fetch(&type, &value, &traceback); + PyErr_Clear(); + szError = "Python error: "; + if (type != NULL && (pyString=PyObject_Str(type))!=NULL && + (PyString_Check(pyString))) + szError += PyString_AsString(pyString); + else szError += "<unknown exception type> "; + Py_XDECREF(pyString); + + if (value != NULL && (pyString=PyObject_Str(value))!=NULL && + (PyString_Check(pyString))) + { + szError += ": "; + szError += PyString_AsString(value); + } else szError += "<unknown exception data> "; + Py_XDECREF(pyString); + + Py_XDECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + } + // clear the thread state PyThreadState_Swap(NULL); // release our hold on the global interpreter PyEval_ReleaseLock(); - return true; + if(retVal) + return false; + else return true; } static KviPointerHashTable<QString,KviPythonInterpreter> * g_pInterpreters = 0; @@ -223,7 +255,7 @@ static bool pythoncore_module_init(KviModule *) PyEval_ReleaseLock(); // Initialize the Python module for KVIrc -// python_init(); + python_init(); g_pInterpreters = new KviPointerHashTable<QString,KviPythonInterpreter>(17,false); g_pInterpreters->setAutoDelete(false); @@ -243,10 +275,9 @@ static bool pythoncore_module_cleanup(KviModule *) // shut down the interpreter PyEval_AcquireLock(); + PyThreadState_Swap(mainThreadState); + PyEval_ReleaseLock(); Py_Finalize(); - - // Close the intepreter - Py_Exit(0); #endif // COMPILE_PYTHON_SUPPORT return true; |
