From 1a9a7ff002007b9e1a7b5d697367ec88cc3c603f Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 14 Mar 2005 21:04:03 +0000 Subject: [PATCH] PR: Sarge port... --- src/SALOMEGUI/PyInterp_PyQt.cxx | 13 ++++++-- src/SALOMEGUI/PyInterp_base.cxx | 46 +++++++++++++++++------------ src/SALOMEGUI/PyInterp_base.h | 2 ++ src/SALOMEGUI/QAD_Desktop.cxx | 4 +++ src/SALOMEGUI/QAD_PyInterp.cxx | 12 ++++++-- src/SALOMEGUI/QAD_Study.cxx | 1 + src/SALOME_PYQT/Makefile.in | 5 ++-- src/SALOME_PYQT/SALOME_PYQT_GUI.cxx | 6 ++-- 8 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/SALOMEGUI/PyInterp_PyQt.cxx b/src/SALOMEGUI/PyInterp_PyQt.cxx index 9ebf3f1d9..29077ca0e 100644 --- a/src/SALOMEGUI/PyInterp_PyQt.cxx +++ b/src/SALOMEGUI/PyInterp_PyQt.cxx @@ -30,16 +30,25 @@ PyInterp_PyQt::~PyInterp_PyQt() void PyInterp_PyQt::initState() { + /* + * The GIL is assumed to not be held on the call + * The GIL is acquired in initState and will be held on initState exit + * It is the caller responsability to release the lock on exit if needed + */ SCRUTE(PyInterp_base::_gtstate); - //PyLockWrapper aLock(_tstate); _tstate=PyInterp_base::_gtstate; + PyEval_AcquireLock(); PyThreadState_Swap(_tstate); SCRUTE(_tstate); } void PyInterp_PyQt::initContext() { - //PyLockWrapper aLock(_tstate); + /* + * The GIL is assumed to be held + * It is the caller responsability to acquire the GIL before calling initContext + * It will still be held on initContext exit + */ _g = PyDict_New(); // create interpreter dictionnary context PyObject *bimod = PyImport_ImportModule("__builtin__"); PyDict_SetItemString(_g, "__builtins__", bimod); diff --git a/src/SALOMEGUI/PyInterp_base.cxx b/src/SALOMEGUI/PyInterp_base.cxx index 92c2e68ba..1c4879d1d 100644 --- a/src/SALOMEGUI/PyInterp_base.cxx +++ b/src/SALOMEGUI/PyInterp_base.cxx @@ -129,24 +129,7 @@ void PyInterp_base::initialize() _history.clear(); // start a new list of user's commands _ith = _history.begin(); - if(!_gtstate){ - //PyReleaseLock aReleaseLock; - Py_Initialize(); // Initialize the interpreter - PyEval_InitThreads(); // Initialize and acquire the global interpreter lock - PySys_SetArgv(_argc,_argv); // initialize sys.argv - _gtstate = PyThreadState_Get(); - - /* - * salome_shared_modules should be imported only once - */ - salome_shared_modules_module = PyImport_ImportModule("salome_shared_modules"); - if(!salome_shared_modules_module) - { - INFOS("PyInterp_base::initialize() - salome_shared_modules_module == NULL"); - PyErr_Print(); - PyErr_Clear(); - } - } + if(!_gtstate) init_python(); // Here the global lock is released if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "< _history; std::list::iterator _ith; bool _atFirst; diff --git a/src/SALOMEGUI/QAD_Desktop.cxx b/src/SALOMEGUI/QAD_Desktop.cxx index 2d661b579..4a1184355 100644 --- a/src/SALOMEGUI/QAD_Desktop.cxx +++ b/src/SALOMEGUI/QAD_Desktop.cxx @@ -3348,8 +3348,12 @@ SALOMEGUI* QAD_Desktop::getComponentGUI( const QString& component ) dir = QAD_Tools::addSlash(dir) ; #ifdef WNT dir = dir + "libSalomePyQtcmodule.dll" ; +#else +#if SIP_VERS == v4_1 + dir = dir + "SalomePyQt.so" ; #else dir = dir + "libSalomePyQtcmodule.so" ; +#endif #endif MESSAGE ( " GUI library = " << dir ); fileInfo.setFile(dir) ; diff --git a/src/SALOMEGUI/QAD_PyInterp.cxx b/src/SALOMEGUI/QAD_PyInterp.cxx index ac0ddd2b5..a2ea8ac56 100644 --- a/src/SALOMEGUI/QAD_PyInterp.cxx +++ b/src/SALOMEGUI/QAD_PyInterp.cxx @@ -72,7 +72,11 @@ QAD_PyInterp::~QAD_PyInterp() void QAD_PyInterp::initState() { - //PyLockWrapper aLock(_tstate); + /* + * The GIL is acquired and will be held on initState output + * It is the caller responsability to release the lock if needed + */ + PyEval_AcquireLock(); _tstate = Py_NewInterpreter(); // create an interpreter and save current state PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv if(MYDEBUG) MESSAGE("QAD_PyInterp::initState - this = "<getComponentUserName( "KERNEL" ) ); /* create python interpreter */ + QAD_PyInterp::init_python(); // initialize Python out of qthread myInitStudyThread = new TInitStudyThread(myInterp,myMutex); myInitStudyThread->start(); diff --git a/src/SALOME_PYQT/Makefile.in b/src/SALOME_PYQT/Makefile.in index 30a129164..a581f99b1 100644 --- a/src/SALOME_PYQT/Makefile.in +++ b/src/SALOME_PYQT/Makefile.in @@ -42,10 +42,11 @@ MOC_SRC = sipSalomePyQtcmodule_moc.cxx MOC_H = sipSalomePyQtcmodule.h SIP_FILES = SalomePyQt_v4.sip #LDFLAGS+= -lSalomeGUI -LDFLAGS+= -lSalomeGUI -module +#LDFLAGS+= -lSalomeGUI -module +LDFLAGS+= -shared -lSalomeGUI # Libraries targets -LIB = SalomePyQt.la +LIB = SalomePyQt.so else ifeq ($(SIP_VERS),new2) SIP_FLAGS = -t WS_X11 -t Qt_3_0_5 -s ".cc" -c $(CURDIR) -I $(PYQT_SIPS) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx index c8a3eabcc..ce1ae9842 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx @@ -47,14 +47,14 @@ void SALOME_PYQT_GUI::setWorkSpace() PyLockWrapper aLock = interp->GetLockWrapper(); // Try to import qt module. If it's not possible don't go on - PyObjWrapper qtmodule(PyImport_ImportModule("qt")); + PyObjWrapper qtmodule(PyImport_ImportModule("SalomePyQt")); if(!qtmodule){ PyErr_Print(); return ; } - PyObjWrapper pyws(sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(), - sipClass_QWorkspace)); + QWorkspace *sipRes=QAD_Application::getDesktop()->getMainFrame(); + PyObjWrapper pyws(sipMapCppToSelf( sipRes, sipClass_QWorkspace)); PyObjWrapper res(PyObject_CallMethod(_module,"setWorkSpace","O",pyws.get())); SCRUTE(pyws->ob_refcnt); if(!res){ -- 2.39.2