]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29150] : Fix KERNEL tests and usage of RAII in Container_i.cxx
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 4 Jan 2024 09:14:54 +0000 (10:14 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 4 Jan 2024 09:14:54 +0000 (10:14 +0100)
src/Container/Container_i.cxx
src/Container/SALOME_Container.py
src/Launcher/KernelLauncher.cxx

index 1362635a844a9c760dc1c166ef80326fcad075e5..07fa5c8661d6d0419318987ac2ae7e499bac2ff6 100644 (file)
@@ -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)
index b609dcb49aa3496bdbdcb5acbfc3196f369f7714..d3bbc084aeef8f5039e57ebd36649f5f06101acc 100644 (file)
@@ -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
index ba5db808539dc409ff8a37b49fe3d8ebab3ad12d..31297ad643d45b58065599a6648de7854a938528 100644 (file)
@@ -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;