From: Anthony Geay Date: Thu, 4 Jan 2024 09:14:54 +0000 (+0100) Subject: [EDF29150] : Fix KERNEL tests and usage of RAII in Container_i.cxx X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8bef0187aad6254b6e68430c9cceff96d456a7bd;p=modules%2Fkernel.git [EDF29150] : Fix KERNEL tests and usage of RAII in Container_i.cxx --- diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 1362635a8..07fa5c866 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -326,7 +326,7 @@ void Abstract_Engines_Container_i::locallogfilename(const char *name) { AutoGIL gstate; _localfilename = name; - PyObject *result = PyObject_CallMethod(_pyCont,(char*)"setLogFileName","s",name,nullptr); + AutoPyRef result = PyObject_CallMethod(_pyCont,(char*)"setLogFileName","s",name,nullptr); if (PyErr_Occurred()) { std::string error("can not set logfilename"); @@ -338,7 +338,7 @@ void Abstract_Engines_Container_i::locallogfilename(const char *name) CORBA::Long Abstract_Engines_Container_i::monitoringtimeresms() { AutoGIL gstate; - PyObject *result = PyObject_CallMethod(_pyCont,(char*)"monitoringtimeresms",nullptr); + AutoPyRef result = PyObject_CallMethod(_pyCont,(char*)"monitoringtimeresms",nullptr); if (PyErr_Occurred()) { std::string error("can not retrieve time interval between 2 measures"); @@ -346,21 +346,19 @@ CORBA::Long Abstract_Engines_Container_i::monitoringtimeresms() THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR); } CORBA::Long ret = PyLong_AsLong( result ); - Py_XDECREF(result); return ret; } void Abstract_Engines_Container_i::monitoringtimeresms(CORBA::Long intervalInMs) { AutoGIL gstate; - PyObject *result = PyObject_CallMethod(_pyCont,(char*)"SetMonitoringtimeresms","i",intervalInMs,nullptr); + AutoPyRef result = PyObject_CallMethod(_pyCont,(char*)"SetMonitoringtimeresms","i",intervalInMs,nullptr); if (PyErr_Occurred()) { std::string error("can not set time interval between 2 measures"); PyErr_Print(); THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR); } - Py_XDECREF(result); } void Abstract_Engines_Container_i::verbosity(bool& activated, CORBA::String_out level) @@ -375,7 +373,7 @@ void Abstract_Engines_Container_i::setVerbosity(bool activated, const char *leve SALOME::SetVerbosityLevelStr( level ); { AutoGIL gstate; - PyObject *res = PyObject_CallMethod(_pyCont, + AutoPyRef res = PyObject_CallMethod(_pyCont, (char*)"positionVerbosityOfLogger",NULL); if(res==NULL) { @@ -437,11 +435,9 @@ CORBA::Long Abstract_Engines_Container_i::getNumberOfCPUCores() { AutoGIL gstate; PyObject *module = PyImport_ImportModuleNoBlock((char*)"salome_psutil"); - PyObject *result = PyObject_CallMethod(module, + AutoPyRef result = PyObject_CallMethod(module, (char*)"getNumberOfCPUCores", NULL); int n = PyLong_AsLong(result); - Py_DECREF(result); - return (CORBA::Long)n; } @@ -599,7 +595,7 @@ Engines::vectorOfDouble* Abstract_Engines_Container_i::loadOfCPUCores() { AutoGIL gstate; PyObject *module = PyImport_ImportModuleNoBlock((char*)"salome_psutil"); - PyObject *result = PyObject_CallMethod(module, + AutoPyRef result = PyObject_CallMethod(module, (char*)"loadOfCPUCores", "s", _load_script.c_str()); if (PyErr_Occurred()) @@ -615,7 +611,6 @@ Engines::vectorOfDouble* Abstract_Engines_Container_i::loadOfCPUCores() int n = this->getNumberOfCPUCores(); if (!PyList_Check(result) || PyList_Size(result) != n) { // bad number of cores - Py_DECREF(result); SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; es.text = "wrong number of cores"; @@ -630,7 +625,6 @@ Engines::vectorOfDouble* Abstract_Engines_Container_i::loadOfCPUCores() if (foo < 0.0 || foo > 1.0) { // value not in [0, 1] range - Py_DECREF(result); SALOME::ExceptionStruct es; es.type = SALOME::INTERNAL_ERROR; es.text = "load not in [0, 1] range"; @@ -639,8 +633,6 @@ Engines::vectorOfDouble* Abstract_Engines_Container_i::loadOfCPUCores() loads[i] = foo; } - Py_DECREF(result); - return loads._retn(); } @@ -680,10 +672,9 @@ CORBA::Long Abstract_Engines_Container_i::getTotalPhysicalMemory() { AutoGIL gstate; PyObject *module = PyImport_ImportModuleNoBlock((char*)"salome_psutil"); - PyObject *result = PyObject_CallMethod(module, + AutoPyRef result = PyObject_CallMethod(module, (char*)"getTotalPhysicalMemory", NULL); int n = PyLong_AsLong(result); - Py_DECREF(result); return (CORBA::Long)n; } @@ -699,10 +690,9 @@ CORBA::Long Abstract_Engines_Container_i::getTotalPhysicalMemoryInUse() { AutoGIL gstate; PyObject *module = PyImport_ImportModuleNoBlock((char*)"salome_psutil"); - PyObject *result = PyObject_CallMethod(module, + AutoPyRef result = PyObject_CallMethod(module, (char*)"getTotalPhysicalMemoryInUse", NULL); int n = PyLong_AsLong(result); - Py_DECREF(result); return (CORBA::Long)n; } @@ -718,10 +708,9 @@ CORBA::Long Abstract_Engines_Container_i::getTotalPhysicalMemoryInUseByMe() { AutoGIL gstate; PyObject *module = PyImport_ImportModuleNoBlock((char*)"salome_psutil"); - PyObject *result = PyObject_CallMethod(module, + AutoPyRef result = PyObject_CallMethod(module, (char*)"getTotalPhysicalMemoryInUseByMe", NULL); int n = PyLong_AsLong(result); - Py_DECREF(result); return (CORBA::Long)n; } @@ -987,12 +976,11 @@ Abstract_Engines_Container_i::load_component_PythonImplementation(const char* co { AutoGIL gstate; - PyObject *result = PyObject_CallMethod(_pyCont, + AutoPyRef result = PyObject_CallMethod(_pyCont, (char*)"import_component", (char*)"s",componentName); reason=PyUnicode_AsUTF8(result); - Py_XDECREF(result); SCRUTE(reason); } @@ -1404,7 +1392,7 @@ Abstract_Engines_Container_i::createPythonInstance(std::string CompName, std::string iors; { AutoGIL gstate; - PyObject *result = PyObject_CallMethod(_pyCont, + AutoPyRef result = PyObject_CallMethod(_pyCont, (char*)"create_component_instance", (char*)"ss", CompName.c_str(), @@ -1414,7 +1402,6 @@ Abstract_Engines_Container_i::createPythonInstance(std::string CompName, PyArg_ParseTuple(result,"ss", &ior, &error); iors = ior; reason=error; - Py_DECREF(result); } if( iors!="" ) @@ -1445,7 +1432,7 @@ Abstract_Engines_Container_i::create_python_service_instance(const char * CompNa char * _ior = nullptr; { AutoGIL gstate; - PyObject *result = PyObject_CallMethod(_pyCont, + AutoPyRef result = PyObject_CallMethod(_pyCont, (char*)"create_component_instance", (char*)"ss", CompName, @@ -1455,7 +1442,6 @@ Abstract_Engines_Container_i::create_python_service_instance(const char * CompNa PyArg_ParseTuple(result,"ss", &ior, &error); reason = CORBA::string_dup(error); _ior = CORBA::string_dup(ior); - Py_DECREF(result); } return _ior; } @@ -2201,12 +2187,12 @@ Engines::PyScriptNode_ptr Abstract_Engines_Container_i::createPyScriptNode(const std::string astr; { AutoGIL gstate; - PyObject *res = PyObject_CallMethod(_pyCont, + AutoPyRef res = PyObject_CallMethod(_pyCont, (char*)"create_pyscriptnode", (char*)"ss", nodeName, code); - if(res==NULL) + if( res.isNull() ) { //internal error PyErr_Print(); @@ -2218,7 +2204,6 @@ Engines::PyScriptNode_ptr Abstract_Engines_Container_i::createPyScriptNode(const ierr=PyLong_AsLong(PyTuple_GetItem(res,0)); PyObject* result=PyTuple_GetItem(res,1); astr = PyUnicode_AsUTF8(result); - Py_DECREF(res); } if(ierr==0) diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py index b609dcb49..d3bbc084a 100644 --- a/src/Container/SALOME_Container.py +++ b/src/Container/SALOME_Container.py @@ -46,7 +46,7 @@ import logging from SALOME_utilities import * from Utils_Identity import getShortHostName from salome_utils import verbose -from KernelBasis import VerbosityActivated +from KernelBasis import VerbosityActivated,getSSLMode #============================================================================= @@ -159,7 +159,9 @@ class SALOME_Container_i: def create_pyscriptnode(self,nodeName,code): try: - logscript = self._log.addScript(nodeName,code) + logscript = None + if getSSLMode(): + logscript = self._log.addScript(nodeName,code) node=SALOME_PyNode.PyScriptNode_i(nodeName,code,self._poa,self, logscript) id_o = self._poa.activate_object(node) comp_o = self._poa.id_to_reference(id_o) @@ -180,7 +182,8 @@ class SALOME_Container_i: return self._timeIntervalInMs def setLogFileName(self, logFileName): - self._log = self.logm.declareContainer( self._containerName, logFileName ) + if getSSLMode(): + self._log = self.logm.declareContainer( self._containerName, logFileName ) def SetMonitoringtimeresms(self , value): self._timeIntervalInMs = value diff --git a/src/Launcher/KernelLauncher.cxx b/src/Launcher/KernelLauncher.cxx index ba5db8085..31297ad64 100644 --- a/src/Launcher/KernelLauncher.cxx +++ b/src/Launcher/KernelLauncher.cxx @@ -90,7 +90,13 @@ std::string GetLogManagerInstance() CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); // - PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true); + CORBA::PolicyList policies; + policies.length(1); + PortableServer::POAManager_var pman = root_poa->the_POAManager(); + PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol); + PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOAForLogManager",pman,policies); + threadPol->destroy(); // SALOME_CPythonHelper *cPyh(SALOME_CPythonHelper::Singleton()); SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService;