]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[PY3] Fixing SalomeSDS / cmp removal in Py3
authorNicolas Geimer <nicolas.geimer@edf.fr>
Fri, 21 Apr 2017 14:15:43 +0000 (16:15 +0200)
committerNicolas Geimer <nicolas.geimer@edf.fr>
Fri, 21 Apr 2017 14:15:43 +0000 (16:15 +0200)
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx
src/SALOMESDS/SalomeSDSClt.py

index 3892e1ec4526a3ff23191775882e05cca0f4dcde..99ea0d6755885d159f5813a11d7ba403c6a501d4 100644 (file)
@@ -258,7 +258,7 @@ void DataScopeServerBase::initializePython(int argc, char *argv[])
     }
   _locals=PyDict_New();
   PyObject *tmp(PyList_New(0));
-  _pickler=PyImport_ImportModuleLevel(const_cast<char *>("pickle"),_globals,_locals,tmp,-1);
+  _pickler=PyImport_ImportModuleLevel(const_cast<char *>("pickle"),_globals,_locals,tmp,0);
 }
 
 void DataScopeServerBase::registerToSalomePiDict() const
@@ -623,24 +623,18 @@ void DataScopeServerTransaction::addWaitKey(KeyWaiter *kw)
 
 void DataScopeServerTransaction::pingKey(PyObject *keyObj)
 {
-  PyObject *cmpObj(getPyCmpFunc());
-  if(!keyObj)
-    throw Exception("ataScopeServerTransaction::pingKey : Key Object is NULL !");
-  PyObject *args(PyTuple_New(2));
-  PyTuple_SetItem(args,0,keyObj); Py_XINCREF(keyObj);
   std::size_t ii(0);
   // this part does nothing except to be sure that in notify key all will be OK.
   for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++)
     {
       PyObject *waitKey((*it)->getKeyPyObj());
-      PyTuple_SetItem(args,1,waitKey); Py_XINCREF(waitKey);
-      PyObject *res(PyObject_CallObject(cmpObj,args));
+      PyObject *res(PyObject_CallMethodObjArgs(keyObj, PyUnicode_DecodeASCII("__ne__", 6, NULL), waitKey));
       if(res==NULL)
         {
           std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " error during cmp(k,wk[i]) !";
           throw Exception(oss.str());
         }
-      PyLong_AsLong(res);
+      PyLong_AsLong(res); // res is bool, but it s ok since __int__ is called
       if(PyErr_Occurred())
         {
           std::ostringstream oss; oss << "DataScopeServerTransaction::pingKey : for object id #" << ii << " error during interpretation of cmp(k,wk[i]) !";
@@ -652,11 +646,6 @@ void DataScopeServerTransaction::pingKey(PyObject *keyObj)
 
 void DataScopeServerTransaction::notifyKey(const std::string& varName, PyObject *keyObj, PyObject *valueObj)
 {
-  PyObject *cmpObj(getPyCmpFunc());
-  if(!keyObj)
-    throw Exception("DataScopeServerTransaction::notifyKey : MAIN INTERNAL ERROR ! Key Object is NULL !");
-  PyObject *args(PyTuple_New(2));
-  PyTuple_SetItem(args,0,keyObj); Py_XINCREF(keyObj);
   std::size_t ii(0);
   std::list< KeyWaiter *> newList,listOfEltToWakeUp;
   for(std::list< KeyWaiter *>::iterator it=_waiting_keys.begin();it!=_waiting_keys.end();it++,ii++)
@@ -667,14 +656,13 @@ void DataScopeServerTransaction::notifyKey(const std::string& varName, PyObject
           continue;
         }
       PyObject *waitKey((*it)->getKeyPyObj());
-      PyTuple_SetItem(args,1,waitKey); Py_XINCREF(waitKey);
-      PyObject *res(PyObject_CallObject(cmpObj,args));
+      PyObject *res(PyObject_CallMethodObjArgs(keyObj, PyUnicode_DecodeASCII("__ne__", 6, NULL), waitKey));
       if(res==NULL)
         {
           std::ostringstream oss; oss << "DataScopeServerTransaction::notifyKey : MAIN INTERNAL ERROR ! for object id #" << ii << " error during cmp(k,wk[i]) !";
           throw Exception(oss.str());
         }
-      long resCpp(PyLong_AsLong(res));
+      long resCpp(PyLong_AsLong(res)); // res is bool, but it s ok since __int__ is called
       if(PyErr_Occurred())
         {
           std::ostringstream oss; oss << "DataScopeServerTransaction::notifyKey : MAIN INTERNAL ERROR ! for object id #" << ii << " error during interpretation of cmp(k,wk[i]) !";
@@ -845,23 +833,6 @@ void DataScopeServerTransaction::atomicApply(const SALOME::ListOfTransaction& tr
     transactionsCpp[i]->notify();
 }
 
-/*!
- * Returns borrowed reference.
- */
-PyObject *DataScopeServerTransaction::getPyCmpFunc()
-{
-  PyObject *builtins(PyDict_GetItemString(_globals,"__builtins__"));//borrowed
-  if(builtins==NULL)
-    throw Exception("Fail to find reference to builtins !");
-  PyObject *builtins2(PyModule_GetDict(builtins));//borrowed
-  if(builtins2==NULL)
-    throw Exception("Fail to invoke __dict__ on builtins !");
-  PyObject *cmpObj(PyDict_GetItemString(builtins2,"cmp"));
-  if(cmpObj==NULL)
-    throw Exception("Fail to find cmp in __builtins__ !");
-  return cmpObj;
-}
-
 DataScopeServerTransaction::~DataScopeServerTransaction()
 {
 }
index c814dd3ec18242247e7505f81d4d6bf7627fac37..fb7c8671b5a446c981db3f2aed9626a7d23f4c98 100644 (file)
@@ -146,8 +146,6 @@ namespace SALOMESDS
     SALOME::KeyWaiter_ptr waitForKeyInVar(const char *varName, const SALOME::ByteVec& keyVal);
     SALOME::KeyWaiter_ptr waitForKeyInVarAndKillIt(const char *varName, const SALOME::ByteVec& keyVal, SALOME::Transaction_out transac);
     void atomicApply(const SALOME::ListOfTransaction& transactions);
-  private:
-    PyObject *getPyCmpFunc();
   private:
     PortableServer::POA_var _poa_for_key_waiter;
     std::list< KeyWaiter * > _waiting_keys;
index 8e219d27f335cb708c87b9863fbc0151e4e441cc..6257bbaacf94e693530f4f3fb3939e80aa55b3e2 100644 (file)
@@ -156,7 +156,7 @@ std::string PickelizedPyObjServer::Pickelize(PyObject *obj, DataScopeServerBase
 {
   PyObject *args(PyTuple_New(2));
   PyTuple_SetItem(args,0,obj);
-  PyTuple_SetItem(args,1,PyLong_FromLong(2));// because "assert(cPickle.HIGHEST_PROTOCOL is 2)"
+  PyTuple_SetItem(args,1,PyLong_FromLong(3));// because "assert(pickle.HIGHEST_PROTOCOL is 3)"
   PyObject *selfMeth(PyObject_GetAttrString(dsb->getPickler(),"dumps"));
   PyObject *retPy(PyObject_CallObject(selfMeth,args));
   Py_XDECREF(selfMeth);
index 854df7370c728ec4556057753f38f5f053b7ea6b..c20c5b9366eb3973af5cf1289fc40a61c2b59378 100644 (file)
@@ -263,8 +263,11 @@ class Float(WrappedType,SALOMEWrappedStdType.Float):
     def __imul__(self,*args):
         return self.local_copy().__mul__(*args)
 
-    def __idiv__(self,*args):
-        return self.local_copy().__div__(*args)
+    def __itruediv__(self,*args):
+        return self.local_copy().__truediv__(*args)
+
+    def __ifloordiv__(self,*args):
+        return self.local_copy().__floordiv__(*args)
 
     def __add__(self,*args):
         return self.local_copy().__add__(*args)
@@ -275,8 +278,11 @@ class Float(WrappedType,SALOMEWrappedStdType.Float):
     def __mul__(self,*args):
         return self.local_copy().__mul__(*args)
 
-    def __div__(self,*args):
-        return self.local_copy().__div__(*args)
+    def __floordiv__(self,*args):
+        return self.local_copy().__floordiv__(*args)
+
+    def __truediv__(self,*args):
+        return self.local_copy().__truediv__(*args)
     
     def __pow__(self,*args):
         return self.local_copy().__pow__(*args)
@@ -321,8 +327,11 @@ class Int(WrappedType,SALOMEWrappedStdType.Int):
     def __imod__(self,*args):
         return self.local_copy().__mod__(*args)
     
-    def __idiv__(self,*args):
-        return self.local_copy().__div__(*args)
+    def __itruediv__(self,*args):
+        return self.local_copy().__truediv__(*args)
+    
+    def __ifloordiv__(self,*args):
+        return self.local_copy().__floordiv__(*args)
 
     def __add__(self,*args):
         return self.local_copy().__add__(*args)
@@ -336,9 +345,12 @@ class Int(WrappedType,SALOMEWrappedStdType.Int):
     def __mod__(self,*args):
         return self.local_copy().__mod__(*args)
 
-    def __div__(self,*args):
-        return self.local_copy().__div__(*args)
-    
+    def __truediv__(self,*args):
+        return self.local_copy().__truediv__(*args)
+
+    def __floordiv__(self,*args):
+        return self.local_copy().__floordiv__(*args)
+
     def __pow__(self,*args):
         return self.local_copy().__pow__(*args)