]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
A big problem for int32. Need investigation.
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 3 Mar 2015 18:08:07 +0000 (19:08 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 3 Mar 2015 18:08:07 +0000 (19:08 +0100)
src/MEDCoupling_Swig/CMakeLists.txt
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingFinalize.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDCoupling_Swig/MEDCouplingRemapper.i

index 28c1d951af747d41e87eeb4f167a0520bac2b4eb..108897c53d9a83060acfc51fc54f8593ac5a1125 100644 (file)
@@ -90,4 +90,6 @@ SET_TESTS_PROPERTIES(MEDCouplingRemapperTest PROPERTIES ENVIRONMENT "${tests_env
 IF(NUMPY_FOUND)
   ADD_TEST(MEDCouplingNumPyTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingNumPyTest.py)
   SET_TESTS_PROPERTIES(MEDCouplingNumPyTest PROPERTIES ENVIRONMENT "${tests_env}")
+  ADD_TEST(MEDCouplingPickleTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MEDCouplingPickleTest.py)
+  SET_TESTS_PROPERTIES(MEDCouplingPickleTest PROPERTIES ENVIRONMENT "${tests_env}")
 ENDIF(NUMPY_FOUND)
index 2091a046e208f74657a3939156cfbb2d63fb18eb..02eb0c7680e76ee358fa6110116e664620b414be 100644 (file)
@@ -53,6 +53,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args):
 def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args):
     import _MEDCoupling
     return _MEDCoupling.MEDCouplingFieldDouble____ipow___(self, self, *args)
+def ParaMEDMEMDataArrayIntnew(cls,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____new___(cls,args)
 def ParaMEDMEMDataArrayIntIadd(self,*args):
     import _MEDCoupling
     return _MEDCoupling.DataArrayInt____iadd___(self, self, *args)
index 7d6bafb8b59a6c5248f32cecacfa91a24ce2b318..12502f150fbb1ae57cbb448b6e6a35f8c7dbe7af 100644 (file)
@@ -25,6 +25,7 @@ DataArrayDouble.__imul__=ParaMEDMEMDataArrayDoubleImul
 DataArrayDouble.__idiv__=ParaMEDMEMDataArrayDoubleIdiv
 DataArrayDouble.__ipow__=ParaMEDMEMDataArrayDoubleIpow
 
+DataArrayInt.__new__=classmethod(ParaMEDMEMDataArrayIntnew)
 DataArrayInt.__iadd__=ParaMEDMEMDataArrayIntIadd
 DataArrayInt.__isub__=ParaMEDMEMDataArrayIntIsub
 DataArrayInt.__imul__=ParaMEDMEMDataArrayIntImul
@@ -62,6 +63,7 @@ del ParaMEDMEMMEDCouplingFieldDoubleIsub
 del ParaMEDMEMMEDCouplingFieldDoubleImul
 del ParaMEDMEMMEDCouplingFieldDoubleIdiv
 del ParaMEDMEMMEDCouplingFieldDoubleIpow
+del ParaMEDMEMDataArrayIntnew
 del ParaMEDMEMDataArrayIntIadd
 del ParaMEDMEMDataArrayIntIsub
 del ParaMEDMEMDataArrayIntImul
index 561ecb8209de724cdac775ddc34f2726c2d101d8..ef5df069e47913dba63b5fafc8b4500edddc96e5 100644 (file)
@@ -476,6 +476,41 @@ namespace ParaMEDMEM
         GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
         return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,"");
       }
+
+      PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
+      {
+        PyObject *ret(PyTuple_New(2));
+        std::string a0(self->getName());
+        const std::vector<std::string> &a1(self->getInfoOnComponents());
+        PyTuple_SetItem(ret,0,PyString_FromString(a0.c_str()));
+        //
+        int sz(a1.size());
+        PyObject *ret1(PyList_New(sz));
+        for(int i=0;i<sz;i++)
+          PyList_SetItem(ret1,i,PyString_FromString(a1[i].c_str()));
+        PyTuple_SetItem(ret,1,ret1);
+        //
+        return ret;
+      }
+
+      void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+      {
+        static const char MSG[]="DataArrayDouble.__setstate__ : expected input is a tuple of size 2 with string as 1st arg and list of string as 2nd arg !";
+        if(!PyTuple_Check(inp))
+          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid input ! Invalid overwrite of __getstate__ ?");
+        int sz(PyTuple_Size(inp));
+        if(sz!=2)
+          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid tuple in input ! Should be of size 2 ! Invalid overwrite of __getstate__ ?");
+        PyObject *a0(PyTuple_GetItem(inp,0));
+        if(!PyString_Check(a0))
+          throw INTERP_KERNEL::Exception(MSG);
+        PyObject *a1(PyTuple_GetItem(inp,1));
+        std::vector<std::string> a1cpp;
+        if(!fillStringVector(a1,a1cpp))
+          throw INTERP_KERNEL::Exception(MSG);
+        self->setName(PyString_AsString(a0));
+        self->setInfoOnComponents(a1cpp);
+      }
     }
   };
   
@@ -2231,41 +2266,6 @@ namespace ParaMEDMEM
         throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
 #endif
       }
-      
-      PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
-      {
-        PyObject *ret(PyTuple_New(2));
-        std::string a0(self->getName());
-        const std::vector<std::string> &a1(self->getInfoOnComponents());
-        PyTuple_SetItem(ret,0,PyString_FromString(a0.c_str()));
-        //
-        int sz(a1.size());
-        PyObject *ret1(PyList_New(sz));
-        for(int i=0;i<sz;i++)
-          PyList_SetItem(ret1,i,PyString_FromString(a1[i].c_str()));
-        PyTuple_SetItem(ret,1,ret1);
-        //
-        return ret;
-      }
-
-      void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
-      {
-        static const char MSG[]="DataArrayDouble.__setstate__ : expected input is a tuple of size 2 with string as 1st arg and list of string as 2nd arg !";
-        if(!PyTuple_Check(inp))
-          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid input ! Invalid overwrite of __getstate__ ?");
-        int sz(PyTuple_Size(inp));
-        if(sz!=2)
-          throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid tuple in input ! Should be of size 2 ! Invalid overwrite of __getstate__ ?");
-        PyObject *a0(PyTuple_GetItem(inp,0));
-        if(!PyString_Check(a0))
-          throw INTERP_KERNEL::Exception(MSG);
-        PyObject *a1(PyTuple_GetItem(inp,1));
-        std::vector<std::string> a1cpp;
-        if(!fillStringVector(a1,a1cpp))
-          throw INTERP_KERNEL::Exception(MSG);
-        self->setName(PyString_AsString(a0));
-        self->setInfoOnComponents(a1cpp);
-      }
     }
   };
 
@@ -4570,6 +4570,66 @@ namespace ParaMEDMEM
         PyTuple_SetItem(pyRet,1,ret1Py);
         return pyRet;
       }
+      
+      // serialization
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+      {
+        static const char MSG[]="DataArrayInt.__new__ : the args in input is expected to be a tuple of size 2 !";
+        if(!PyTuple_Check(args))
+          throw INTERP_KERNEL::Exception(MSG);
+        PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
+        PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
+        PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
+        //
+        PyObject *tmp0(PyTuple_New(1));
+        PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
+        PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
+        Py_DECREF(tmp0);
+        Py_DECREF(selfMeth);
+        PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
+        int sz(PyTuple_Size(args));
+        
+        if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
+          {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
+            PyObject *zeNumpyRepr(0);
+            {
+              PyObject *tmp1(PyInt_FromLong(0));
+              zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
+              Py_DECREF(tmp1);
+            }
+            {
+              PyObject *tmp3(PyTuple_New(1));
+              PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
+              // agy : WHY ! I don't know but valgrind complains strongly if not done !
+              // Question is why double does not need it ? It leads to mem leak !
+              //Py_XINCREF(zeNumpyRepr);
+              PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
+              Py_XDECREF(tmp2);
+              Py_DECREF(tmp3);
+            }
+          }
+        Py_DECREF(initMeth);
+        return instance;
+      }
+      
+      PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+      {
+#ifdef WITH_NUMPY
+        if(!self->isAllocated())
+          throw INTERP_KERNEL::Exception("PyWrap of DataArrayInt.__getnewargs__ : self is not allocated !");
+        PyObject *ret(PyTuple_New(1));
+        PyObject *ret0(PyDict_New());
+        PyObject *numpyArryObj(ParaMEDMEM_DataArrayInt_toNumPyArray(self));
+        {// create a dict to discriminite in __new__ if __init__ should be called. Not beautiful but not idea ...
+          PyObject *tmp1(PyInt_FromLong(0));
+          PyDict_SetItem(ret0,tmp1,numpyArryObj); Py_DECREF(tmp1); Py_DECREF(numpyArryObj);
+          PyTuple_SetItem(ret,0,ret0);
+        }
+        return ret;
+#else
+        throw INTERP_KERNEL::Exception("PyWrap of DataArrayInt.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
+#endif
+      }
     }
   };
 
index bb07661b77457c7d0dfcfb4757418061f8730b09..b1c082cab59680f8883402dd4e28d6f83dcdd249 100644 (file)
@@ -136,6 +136,9 @@ def ParaMEDMEMMEDCouplingFieldDoubleIdiv(self,*args):
 def ParaMEDMEMMEDCouplingFieldDoubleIpow(self,*args):
     import _MEDCouplingRemapper
     return _MEDCouplingRemapper.MEDCouplingFieldDouble____ipow___(self, self, *args)
+def ParaMEDMEMDataArrayIntnew(cls,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayInt____new___(cls,args)
 def ParaMEDMEMDataArrayIntIadd(self,*args):
     import _MEDCouplingRemapper
     return _MEDCouplingRemapper.DataArrayInt____iadd___(self, self, *args)