From: Nicolas Geimer Date: Fri, 21 Apr 2017 14:15:43 +0000 (+0200) Subject: [PY3] Fixing SalomeSDS / cmp removal in Py3 X-Git-Tag: V9_0_0~25^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ce1aa701ce6fd8bf397ec4a0289f2347270195c7;p=modules%2Fkernel.git [PY3] Fixing SalomeSDS / cmp removal in Py3 --- diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 3892e1ec4..99ea0d675 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -258,7 +258,7 @@ void DataScopeServerBase::initializePython(int argc, char *argv[]) } _locals=PyDict_New(); PyObject *tmp(PyList_New(0)); - _pickler=PyImport_ImportModuleLevel(const_cast("pickle"),_globals,_locals,tmp,-1); + _pickler=PyImport_ImportModuleLevel(const_cast("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() { } diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index c814dd3ec..fb7c8671b 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -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; diff --git a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx index 8e219d27f..6257bbaac 100644 --- a/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx +++ b/src/SALOMESDS/SALOMESDS_PickelizedPyObjServer.cxx @@ -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); diff --git a/src/SALOMESDS/SalomeSDSClt.py b/src/SALOMESDS/SalomeSDSClt.py index 854df7370..c20c5b936 100644 --- a/src/SALOMESDS/SalomeSDSClt.py +++ b/src/SALOMESDS/SalomeSDSClt.py @@ -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)