Salome HOME
Merge branch 'V9_11_BR'
[modules/yacs.git] / src / runtime / TypeConversions.cxx
index 8a8da3ae020e07c1ccaa460a414bbddb42d67c03..87524ed74d78507e3eb6922b572b7e6f614e25e0 100644 (file)
@@ -33,6 +33,7 @@
 #include "TypeCode.hxx"
 #include "Cstr2d.hxx"
 #include "SALOME_GenericObj.hh"
+#include "PythonNode.hxx"
 
 #include <iostream>
 #include <iomanip>
@@ -679,12 +680,10 @@ namespace YACS
       static inline double convert(const TypeCode *t,PyObject* o,void*)
         {
           double x;
-          if (PyFloat_Check(o))
-            x=PyFloat_AS_DOUBLE(o);
-          else if(PyLong_Check(o))
-            x=PyLong_AsLong(o);
-          else
+          x=PyFloat_AsDouble(o);
+          if( PyErr_Occurred() )
             {
+              PyErr_Restore(nullptr,nullptr,nullptr);
               stringstream msg;
               msg << "Not a python double. ";
 #ifdef _DEVDEBUG_
@@ -702,10 +701,10 @@ namespace YACS
       static inline long convert(const TypeCode *t,PyObject* o,void*)
         {
           long l;
-          if(PyLong_Check(o))
-            l=PyLong_AsLong(o);
-          else
+          l=PyLong_AsLong(o);
+          if( PyErr_Occurred() )
             {
+              PyErr_Restore(nullptr,nullptr,nullptr);
               stringstream msg;
               msg << "Not a python integer. ";
 #ifdef _DEVDEBUG_
@@ -785,9 +784,14 @@ namespace YACS
             }
           if(strncmp(t->id(),"python",6)==0)
             {
+              bool somthingToDo = YACS::ENGINE::PythonEntry::GetDestroyStatus(o);
+              if( somthingToDo )
+                YACS::ENGINE::PythonEntry::DoNotTouchFileIfProxy(o);
               // It's a native Python object pickle it
               PyObject* mod=PyImport_ImportModule("pickle");
               PyObject *pickled=PyObject_CallMethod(mod,(char *)"dumps",(char *)"Oi",o,protocol);
+              if( somthingToDo )
+                YACS::ENGINE::PythonEntry::UnlinkOnDestructorIfProxy(o);
               DEBTRACE(PyObject_Repr(pickled) );
               Py_DECREF(mod);
               if(pickled==NULL)