]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Full OK for DataArrayDouble.
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 3 Mar 2015 15:47:13 +0000 (16:47 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 3 Mar 2015 15:47:13 +0000 (16:47 +0100)
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingFinalize.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDCoupling_Swig/MEDCouplingRemapper.i

index 577c576cecdd19efd6573777b3753a92e2e042b7..2091a046e208f74657a3939156cfbb2d63fb18eb 100644 (file)
@@ -20,6 +20,9 @@
 %include "MEDCouplingCommon.i"
 
 %pythoncode %{
+def ParaMEDMEMDataArrayDoublenew(cls,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____new___(cls,args)
 def ParaMEDMEMDataArrayDoubleIadd(self,*args):
     import _MEDCoupling
     return _MEDCoupling.DataArrayDouble____iadd___(self, self, *args)
index 26097c097a68dc38dca4be4e60662a7a33076025..7d6bafb8b59a6c5248f32cecacfa91a24ce2b318 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 %pythoncode %{
+DataArrayDouble.__new__=classmethod(ParaMEDMEMDataArrayDoublenew)
 DataArrayDouble.__iadd__=ParaMEDMEMDataArrayDoubleIadd
 DataArrayDouble.__isub__=ParaMEDMEMDataArrayDoubleIsub
 DataArrayDouble.__imul__=ParaMEDMEMDataArrayDoubleImul
@@ -51,6 +52,7 @@ DataArrayIntTuple.__imod__=ParaMEDMEMDataArrayIntTupleImod
 DenseMatrix.__iadd__=ParaMEDMEMDenseMatrixIadd
 DenseMatrix.__isub__=ParaMEDMEMDenseMatrixIsub
 
+del ParaMEDMEMDataArrayDoublenew
 del ParaMEDMEMDataArrayDoubleIadd
 del ParaMEDMEMDataArrayDoubleIsub
 del ParaMEDMEMDataArrayDoubleImul
index d7ec98b1dba2d4b67d5ae01a4b621f4575b583a6..561ecb8209de724cdac775ddc34f2726c2d101d8 100644 (file)
@@ -2176,51 +2176,38 @@ namespace ParaMEDMEM
       }
 
       // serialization
-      
-      static PyObject *__new__(PyObject *args) throw(INTERP_KERNEL::Exception)
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
       {
         static const char MSG[]="DataArrayDouble.__new__ : the args in input is expected to be a tuple of size 2 !";
         if(!PyTuple_Check(args))
           throw INTERP_KERNEL::Exception(MSG);
-        //PyObject *globals(PyEval_GetGlobals());//borrowed
-        //PyObject *builtins(PyDict_GetItemString(globals,"__builtins__"));//borrowed
-        //PyObject *builtinsd(PyModule_GetDict(builtins));//borrowed
         PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
         PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
-        //PyObject *obj(PyObject_GetAttrString(builtins,"object"));
         PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
-        //Py_DECREF(obj);
-        /////
+        //
         PyObject *tmp0(PyTuple_New(1));
-        PyTuple_SetItem(tmp0,0,PyTuple_GetItem(args,0)); Py_DECREF(PyTuple_GetItem(args,0));
+        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__"));
-        if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)))
-          { //unserialization requested
-            PyObject *tmp1(PyInt_FromLong(0));
-            PyObject *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);
-            PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
-            Py_DECREF(tmp2);
-            Py_DECREF(tmp3);
-          }
-        else
-          {
-            int sz(PyTuple_Size(args));
-            PyObject *tmp3(PyTuple_New(sz-1));
-            for(int i=0;i<sz-1;i++)
-              {
-                PyObject *tmp0(PyTuple_GetItem(args,i+1)); Py_XINCREF(tmp0);
-                PyTuple_SetItem(tmp3,i,tmp0);
-              }
-            PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
-            Py_DECREF(tmp2);
-            Py_DECREF(tmp3);
+        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);
+              PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
+              Py_XDECREF(tmp2);
+              Py_DECREF(tmp3);
+            }
           }
         Py_DECREF(initMeth);
         return instance;
@@ -2233,10 +2220,12 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : self is not allocated !");
         PyObject *ret(PyTuple_New(1));
         PyObject *ret0(PyDict_New());
-        PyObject *tmp1(PyInt_FromLong(0));
-        PyObject *kw1(ParaMEDMEM_DataArrayDouble_toNumPyArray(self));
-        PyDict_SetItem(ret0,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
-        PyTuple_SetItem(ret,0,ret0);
+        PyObject *numpyArryObj(ParaMEDMEM_DataArrayDouble_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 DataArrayDouble.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !");
index e9ad002c8e190de8f30c161cfb2e047bd207acbc..bb07661b77457c7d0dfcfb4757418061f8730b09 100644 (file)
@@ -103,6 +103,9 @@ namespace ParaMEDMEM
 }
 
 %pythoncode %{
+def ParaMEDMEMDataArrayDoublenew(cls,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDouble____new___(cls,args)
 def ParaMEDMEMDataArrayDoubleIadd(self,*args):
     import _MEDCouplingRemapper
     return _MEDCouplingRemapper.DataArrayDouble____iadd___(self, self, *args)