Salome HOME
AutoGIL.hxx has been factorized to KERNEL PythonCppUtils.hxx
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 24 Aug 2021 14:58:05 +0000 (16:58 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 24 Aug 2021 14:58:05 +0000 (16:58 +0200)
src/evalyfx/YACSEvalSession.cxx
src/evalyfx/YACSEvalSessionInternal.cxx
src/evalyfx/YACSEvalYFXPattern.cxx
src/py2yacs/py2yacs.cxx
src/runtime/CMakeLists.txt
src/runtime/DistributedPythonNode.cxx
src/runtime/PyStdout.cxx
src/runtime/PythonNode.cxx
src/ydfx_gui/YDFXGUISeqInit.cxx

index 0d2f1c828990d19d26c91a32d494ad0acc7fceb4..819e4aba43c3cdb4a1c8e204fd79fccf3184818b 100644 (file)
@@ -21,7 +21,7 @@
 #include "YACSEvalSession.hxx"
 #include "YACSEvalSessionInternal.hxx"
 
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 #include "Exception.hxx"
 
 #include <Python.h>
@@ -37,18 +37,18 @@ const char YACSEvalSession::NSPORT_VAR_NAME[]="NSPORT";
 
 YACSEvalSession::YACSEvalSession():_isAttached(false),_isLaunched(false),_isForcedPyThreadSaved(false),_port(-1),_salomeInstanceModule(0),_salomeInstance(0),_internal(new YACSEvalSessionInternal)
 {
-  YACS::ENGINE::AutoGIL gal;
+  AutoGIL gal;
   _salomeInstanceModule=PyImport_ImportModule(const_cast<char *>("salome_instance"));
 }
 
 YACSEvalSession::~YACSEvalSession()
 {
   delete _internal;
-  YACS::ENGINE::AutoGIL gal;
+  AutoGIL gal;
   if(isLaunched() && !isAttached())
     {
-      YACS::ENGINE::AutoPyRef terminateSession(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("stop")));//new
-      YACS::ENGINE::AutoPyRef res(PyObject_CallObject(terminateSession,0));
+      AutoPyRef terminateSession(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("stop")));//new
+      AutoPyRef res(PyObject_CallObject(terminateSession,0));
     }
   Py_XDECREF(_salomeInstance);
   Py_XDECREF(_salomeInstanceModule);
@@ -58,16 +58,16 @@ void YACSEvalSession::launch()
 {
   if(isLaunched())
     return ;
-  YACS::ENGINE::AutoGIL gal;
+  AutoGIL gal;
   PyObject *salomeInstance(PyObject_GetAttrString(_salomeInstanceModule,const_cast<char *>("SalomeInstance")));//new
   PyObject *startMeth(PyObject_GetAttrString(salomeInstance,const_cast<char *>("start")));
   Py_XDECREF(salomeInstance);
-  YACS::ENGINE::AutoPyRef myArgs(PyTuple_New(0));//new
-  YACS::ENGINE::AutoPyRef myKWArgs(PyDict_New());//new
+  AutoPyRef myArgs(PyTuple_New(0));//new
+  AutoPyRef myKWArgs(PyDict_New());//new
   PyDict_SetItemString(myKWArgs,"shutdown_servers",Py_True);//Py_True ref not stolen
   _salomeInstance=PyObject_Call(startMeth,myArgs,myKWArgs);//new
-  YACS::ENGINE::AutoPyRef getPortMeth(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("get_port")));//new
-  YACS::ENGINE::AutoPyRef portPy(PyObject_CallObject(getPortMeth,0));//new
+  AutoPyRef getPortMeth(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("get_port")));//new
+  AutoPyRef portPy(PyObject_CallObject(getPortMeth,0));//new
   _port=PyLong_AsLong(portPy);
   //
   int dummy;
@@ -79,7 +79,7 @@ void YACSEvalSession::launchUsingCurrentSession()
 {
   if(isLaunched())
     return ;
-  YACS::ENGINE::AutoGIL gal;
+  AutoGIL gal;
   _corbaConfigFileName=GetConfigAndPort(_port);
   _isAttached=true; _isLaunched=true;
 }
@@ -110,23 +110,23 @@ std::string YACSEvalSession::getCorbaConfigFileName() const
 std::string YACSEvalSession::GetPathToAdd()
 {
   std::string ret;
-  YACS::ENGINE::AutoGIL gal;
-  YACS::ENGINE::AutoPyRef osPy(PyImport_ImportModule(const_cast<char *>("os")));//new
+  AutoGIL gal;
+  AutoPyRef osPy(PyImport_ImportModule(const_cast<char *>("os")));//new
   PyObject *kernelRootDir(0);// os.environ["KERNEL_ROOT_DIR"]
   {
-    YACS::ENGINE::AutoPyRef environPy(PyObject_GetAttrString(osPy,const_cast<char *>("environ")));//new
-    YACS::ENGINE::AutoPyRef kernelRootDirStr(PyBytes_FromString(const_cast<char *>(KERNEL_ROOT_DIR)));//new
+    AutoPyRef environPy(PyObject_GetAttrString(osPy,const_cast<char *>("environ")));//new
+    AutoPyRef kernelRootDirStr(PyBytes_FromString(const_cast<char *>(KERNEL_ROOT_DIR)));//new
     kernelRootDir=PyObject_GetItem(environPy,kernelRootDirStr);//new
   }
   {
-    YACS::ENGINE::AutoPyRef pathPy(PyObject_GetAttrString(osPy,const_cast<char *>("path")));//new
-    YACS::ENGINE::AutoPyRef joinPy(PyObject_GetAttrString(pathPy,const_cast<char *>("join")));//new
-    YACS::ENGINE::AutoPyRef myArgs(PyTuple_New(4));
+    AutoPyRef pathPy(PyObject_GetAttrString(osPy,const_cast<char *>("path")));//new
+    AutoPyRef joinPy(PyObject_GetAttrString(pathPy,const_cast<char *>("join")));//new
+    AutoPyRef myArgs(PyTuple_New(4));
     Py_XINCREF(kernelRootDir); PyTuple_SetItem(myArgs,0,kernelRootDir);
     PyTuple_SetItem(myArgs,1,PyBytes_FromString(const_cast<char *>("bin")));
     PyTuple_SetItem(myArgs,2,PyBytes_FromString(const_cast<char *>("salome")));
     PyTuple_SetItem(myArgs,3,PyBytes_FromString(const_cast<char *>("appliskel")));
-    YACS::ENGINE::AutoPyRef res(PyObject_CallObject(joinPy,myArgs));
+    AutoPyRef res(PyObject_CallObject(joinPy,myArgs));
     ret=PyBytes_AsString(res);
   }
   Py_XDECREF(kernelRootDir);
index 45da13bf1ef57c68bb100abfaeeee9f985f9f8d8..2ef842bdc90dd0580922f8ada1ccf0a98765dfe9 100644 (file)
@@ -22,7 +22,7 @@
 #include "YACSEvalSession.hxx"
 
 #include "PyStdout.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 #include "Exception.hxx"
 
 YACSEvalSession::YACSEvalSessionInternal::YACSEvalSessionInternal():_orb(CORBA::ORB::_nil()),_sl(Engines::SalomeLauncher::_nil())
@@ -46,8 +46,8 @@ Engines::SalomeLauncher_var YACSEvalSession::YACSEvalSessionInternal::goFetching
   //
   const char methName[]="goFetchingSalomeLauncherInNS";
   const char fetchPyCmd[]="import salome,CORBA\nsalome.salome_init()\nsl=salome.naming_service.Resolve(\"/SalomeLauncher\")\nif not CORBA.is_nil(sl):\n  return salome.orb.object_to_string(sl)\nelse:\n  raise Exception(\"Impossible to locate salome launcher !\")";
-  YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
-  YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+  AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
+  AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
   std::string ior;
   if (PyUnicode_Check(val))
     ior = PyUnicode_AsUTF8(val);
index 8b5b3b44bcffa9a849bed61a3f2263d6dc14a687..677963adb940750a02277653c3a5baa0f59e966f 100644 (file)
@@ -43,7 +43,7 @@
 #include "InlineNode.hxx"
 #include "ServiceNode.hxx"
 #include "PyStdout.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 
 #include "ResourcesManager.hxx"
 
@@ -886,14 +886,14 @@ std::vector<YACSEvalSeqAny *> YACSEvalYFXGraphGenInteractive::getResults() const
 
 void YACSEvalYFXGraphGenCluster::generateGraph()
 {
-  YACS::ENGINE::AutoGIL agil;
+  AutoGIL agil;
   //
   const char EFXGenFileName[]="EFXGenFileName";
   const char EFXGenContent[]="import getpass,datetime,os\nn=datetime.datetime.now()\nreturn os.path.join(os.path.sep,\"tmp\",\"EvalYFX_%s_%s_%s.xml\"%(getpass.getuser(),n.strftime(\"%d%m%y\"),n.strftime(\"%H%M%S\")))";
   const char EFXGenContent2[]="import getpass,datetime\nn=datetime.datetime.now()\nreturn \"EvalYFX_%s_%s_%s\"%(getpass.getuser(),n.strftime(\"%d%m%y\"),n.strftime(\"%H%M%S\"))";
   //
-  YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent));
-  YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+  AutoPyRef func(YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent));
+  AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
   if (PyUnicode_Check(val))
     _locSchemaFile = PyUnicode_AsUTF8(val);
   else
@@ -927,7 +927,7 @@ void YACSEvalYFXGraphGenCluster::generateGraph()
 
 bool YACSEvalYFXGraphGenCluster::go(const YACSEvalExecParams& params, YACSEvalSession *session) const
 {
-  YACS::ENGINE::AutoGIL agil;
+  AutoGIL agil;
   _errors = "";
   getUndergroundGeneratedGraph()->saveSchema(_locSchemaFile);
   YACSEvalListOfResources *rss(getBoss()->getResourcesInternal());
@@ -1017,8 +1017,8 @@ bool YACSEvalYFXGraphGenCluster::go(const YACSEvalExecParams& params, YACSEvalSe
       oss << "f=open(p,\"r\")" << std::endl;
       oss << "return eval(f.read())";
       std::string zeInput(oss.str());
-      YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy("fetch",zeInput));
-      YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+      AutoPyRef func(YACS::ENGINE::evalPy("fetch",zeInput));
+      AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
       if(!PyList_Check(val))
         throw YACS::Exception("Fetched file does not contain a list !");
       Py_ssize_t sz(PyList_Size(val));
index e4436ec53e6958b04c5d7bd357368bcb2645b78d..9d77835c19d6f521be0e79fd9188156387dd5090 100644 (file)
@@ -22,7 +22,7 @@
 #include "RuntimeSALOME.hxx"
 #include "Proc.hxx"
 #include "InlineNode.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 #include "InputPort.hxx"
 #include "Container.hxx"
 
@@ -180,7 +180,7 @@ void Py2yacs::load(const std::string& python_code)
     _global_errors.clear();
     
     // Py_Initialize();
-    YACS::ENGINE::AutoGIL agil;
+    AutoGIL agil;
     pValue = PyUnicode_FromString(_python_parser_module.c_str());
     pModule = PyImport_Import(pValue);
     Py_DECREF(pValue);
@@ -456,4 +456,4 @@ std::string Py2yacs::getFunctionErrors(const std::string& functionName)const
     buffer << "Function " << functionName << " not found." << std::endl;
   }
   return buffer.str();
-}
\ No newline at end of file
+}
index b2f86dafb4875284eef5cc9a4201397977b7356c..c0e74f647788925c391c9b40eb486f02b9da7400 100644 (file)
@@ -84,7 +84,6 @@ SET(_link_LIBRARIES
 
 SET(YACSRuntimeSALOME_HEADERS
   YACSRuntimeSALOMEExport.hxx 
-  AutoGIL.hxx
   CalStreamPort.hxx
   CORBAComponent.hxx
   CORBACORBAConv.hxx
index 8a26db683d80b81aeff672369a0bff25e1462451..a912dd92aca9fdaf0476f1114ccdd8ed54262ca2 100644 (file)
@@ -23,7 +23,7 @@
 #include "PythonNode.hxx"
 #include "SalomeHPContainer.hxx"
 #include "SalomeContainerTmpForHP.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 
 #include "PythonPorts.hxx"
 #include "YacsTrace.hxx"
index fcb29e6a8de59b8463b219037ab7bce779cc3ad3..0bdee3b99cbfcec0ee7e1d96d9d323089c67f929 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "PyStdout.hxx"
 #include "Exception.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 
 #include <structmember.h>
 
index 42eae744604a18cae10c4709ccda5409cbc5f265..fbc60bb49b2a6e07588d834ce6a750ce3f910ba8 100644 (file)
@@ -21,7 +21,7 @@
 #include "PythonNode.hxx"
 #include "PythonPorts.hxx"
 #include "TypeCode.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 #include "Container.hxx"
 #include "SalomeContainer.hxx"
 #include "SalomeHPContainer.hxx"
index a451d6fce139f050602dedd42b1e6d88da7896f2..3f8663cf03f9c8016d5f4fc655af45705049d6f1 100644 (file)
@@ -33,7 +33,7 @@
 #include <QApplication>
 
 
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
 
 #include "YDFXGUIWrap.hxx"
 #include "YDFXGUIPyThreadSaver.hxx"
 
 const char YDFXGUIStatus::OK_STR[]="OK !";
 
-class AutoPyRef
-{
-public:
-  AutoPyRef(PyObject *pyobj=0):_pyobj(pyobj) { }
-  ~AutoPyRef() { release(); }
-  AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); }
-  AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; }
-  operator PyObject *() { return _pyobj; }
-  void set(PyObject *pyobj) { if(pyobj==_pyobj) return ; release(); _pyobj=pyobj; }
-  PyObject *get() { return _pyobj; }
-  bool isNull() const { return _pyobj==0; }
-  PyObject *retn() { if(_pyobj) Py_XINCREF(_pyobj); return _pyobj; }
-private:
-  void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=0; }
-private:
-  PyObject *_pyobj;
-};
-
 ////////////////////////////
 
 void YDFXGUIDoubleVectHolder::applyOnInput(YACSEvalInputPort *inp) const
@@ -199,7 +181,7 @@ bool YDFXGUISeqSetterT::executeScript(int& sz)
   std::string txt(toPlainText().toStdString());
   YDFXGUIPyThreadSaver::SaveContext(QApplication::instance()->thread());
   {
-    YACS::ENGINE::AutoGIL gal;
+    AutoGIL gal;
     AutoPyRef code(Py_CompileString(txt.c_str(),TMP_FILENAME, Py_file_input));
     if(code.get() == NULL)
       {