]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/runtime/TypeConversions.cxx
Salome HOME
[PYTHON 3] WIP
[modules/yacs.git] / src / runtime / TypeConversions.cxx
index 2134240b340044261e7c6ac3e2f9f94e1fc4dc01..e33fae63449686db82b609e01d1399ed8ce3e348 100644 (file)
@@ -695,8 +695,6 @@ namespace YACS
           double x;
           if (PyFloat_Check(o))
             x=PyFloat_AS_DOUBLE(o);
-          else if (PyInt_Check(o))
-            x=PyInt_AS_LONG(o);
           else if(PyLong_Check(o))
             x=PyLong_AsLong(o);
           else
@@ -718,9 +716,7 @@ namespace YACS
       static inline long convert(const TypeCode *t,PyObject* o,void*)
         {
           long l;
-          if (PyInt_Check(o))
-            l=PyInt_AS_LONG(o);
-          else if(PyLong_Check(o))
+          if(PyLong_Check(o))
             l=PyLong_AsLong(o);
           else
             {
@@ -741,8 +737,8 @@ namespace YACS
       static inline std::string convert(const TypeCode *t,PyObject* o,void*)
         {
           std::string s;
-          if (PyString_Check(o))
-            s= PyString_AS_STRING(o);
+          if (PyBytes_Check(o))
+            s= PyBytes_AS_STRING(o);
           else
             {
               stringstream msg;
@@ -764,8 +760,6 @@ namespace YACS
           bool l;
           if (PyBool_Check(o))
               l=(o==Py_True);
-          else if (PyInt_Check(o))
-              l=(PyInt_AS_LONG(o)!=0);
           else if(PyLong_Check(o))
               l=(PyLong_AsLong(o)!=0);
           else
@@ -786,15 +780,15 @@ namespace YACS
     {
       static inline std::string convert(const TypeCode *t,PyObject* o,void*,int protocol)
         {
-          if (PyString_Check(o) && strncmp(t->id(),"python",6)!=0)
+          if (PyBytes_Check(o) && strncmp(t->id(),"python",6)!=0)
             {
               // the objref is used by Python as a string (prefix:value) keep it as a string
-              return PyString_AS_STRING(o);
+              return PyBytes_AS_STRING(o);
             }
           if(strncmp(t->id(),"python",6)==0)
             {
               // It's a native Python object pickle it
-              PyObject* mod=PyImport_ImportModule("cPickle");
+              PyObject* mod=PyImport_ImportModule("pickle");
               PyObject *pickled=PyObject_CallMethod(mod,(char *)"dumps",(char *)"Oi",o,protocol);
               DEBTRACE(PyObject_REPR(pickled) );
               Py_DECREF(mod);
@@ -803,7 +797,7 @@ namespace YACS
                   PyErr_Print();
                   throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
                 }
-              std::string mystr(PyString_AsString(pickled),PyString_Size(pickled));
+              std::string mystr(PyBytes_AsString(pickled),PyBytes_Size(pickled));
               Py_DECREF(pickled);
               return mystr;
             }
@@ -823,7 +817,7 @@ namespace YACS
                   PyErr_Print();
                   throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
                 }
-              std::string mystr=PyString_AsString(pickled);
+              std::string mystr=PyBytes_AsString(pickled);
               Py_DECREF(pickled);
               return mystr;
             }
@@ -836,7 +830,7 @@ namespace YACS
                   PyErr_Print();
                   throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
                 }
-              std::string mystr=PyString_AsString(pystring);
+              std::string mystr=PyBytes_AsString(pystring);
               Py_DECREF(pystring);
               return mystr;
             }
@@ -954,7 +948,7 @@ namespace YACS
     {
       static inline PyObject* convert(const TypeCode *t,std::string& o)
         {
-          return PyString_FromString(o.c_str());
+          return PyBytes_FromString(o.c_str());
         }
     };
     template <>
@@ -978,12 +972,12 @@ namespace YACS
           if(t->isA(Runtime::_tc_file))
             {
               //It's an objref file. Convert it specially
-              return PyString_FromString(o.c_str());
+              return PyBytes_FromString(o.c_str());
             }
           if(strncmp(t->id(),"python",6)==0)
             {
               //It's a python pickled object, unpickled it
-              PyObject* mod=PyImport_ImportModule("cPickle");
+              PyObject* mod=PyImport_ImportModule("pickle");
               PyObject *ob=PyObject_CallMethod(mod,(char *)"loads",(char *)"s#",o.c_str(),o.length());
               DEBTRACE(PyObject_REPR(ob));
               Py_DECREF(mod);
@@ -1864,11 +1858,11 @@ namespace YACS
                     }
 
                   PyGILState_STATE gstate = PyGILState_Ensure(); 
-                  PyObject* mod=PyImport_ImportModule("cPickle");
+                  PyObject* mod=PyImport_ImportModule("pickle");
                   PyObject *ob=PyObject_CallMethod(mod,(char *)"loads",(char *)"s#",s,buffer->length());
                   PyObject *pickled=PyObject_CallMethod(mod,(char *)"dumps",(char *)"Oi",ob,protocol);
                   DEBTRACE(PyObject_REPR(pickled));
-                  std::string mystr=PyString_AsString(pickled);
+                  std::string mystr=PyBytes_AsString(pickled);
                   Py_DECREF(mod);
                   Py_DECREF(ob);
                   Py_DECREF(pickled);
@@ -2291,7 +2285,7 @@ namespace YACS
       PyObject *s;
       PyGILState_STATE gstate = PyGILState_Ensure(); 
       s=PyObject_Str(ob);
-      std::string ss(PyString_AsString(s),PyString_Size(s));
+      std::string ss(PyBytes_AsString(s),PyBytes_Size(s));
       Py_DECREF(s);
       PyGILState_Release(gstate);
       return ss;
@@ -2493,8 +2487,6 @@ namespace YACS
       {
         if (PyFloat_Check(o))
           return true;
-        else if (PyInt_Check(o))
-          return true;
         else if(PyLong_Check(o))
           return true;
         else
@@ -2507,7 +2499,7 @@ namespace YACS
     template<>
     inline bool checkInt<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
       {
-          if (PyInt_Check(o) || PyLong_Check(o))
+          if (PyLong_Check(o))
             return true;
           else
             {
@@ -2521,8 +2513,6 @@ namespace YACS
       {
           if (PyBool_Check(o))
               return true;
-          else if (PyInt_Check(o))
-              return true;
           else if(PyLong_Check(o))
               return true;
           else
@@ -2536,7 +2526,7 @@ namespace YACS
     template<>
     inline bool checkString<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
       {
-          if (PyString_Check(o))
+          if (PyBytes_Check(o))
             return true;
           else
             {
@@ -2548,7 +2538,7 @@ namespace YACS
     template<>
     inline bool checkObjref<PYTHONImpl,PyObject*,void*>(const TypeCode *t,PyObject* o,void* aux)
       {
-          if (PyString_Check(o))
+          if (PyBytes_Check(o))
             return true;
           if(strncmp(t->id(),"python",6)==0) // a Python object is expected (it's always true)
             return true;