X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingDataArrayTypemaps.i;h=21f462ba01bb3545ef0dfef7d64f182813dac29b;hb=94566ff4f9e37314014461f7773330f989c9ca09;hp=d1f2da7e148c6f0ac6e222c0843badfa78d83753;hpb=daa2c5dc8a6e6a83230545296fac630603904644;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index d1f2da7e1..21f462ba0 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -82,7 +82,7 @@ void numarrdeal(void *pt, void *wron) { Py_XINCREF(obj); PyArrayObject *objC=reinterpret_cast(obj); - objC->flags|=NPY_OWNDATA; + objC->flags|=NPY_ARRAY_OWNDATA; Py_XDECREF(weakRefOnOwner); Py_XDECREF(obj); } @@ -282,24 +282,36 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order { PyArrayObject *elt0C=reinterpret_cast(elt0); - PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL; - int mask=NPY_OWNDATA; mask=~mask; + PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_ARRAY_OWNDATA)?elt0C:NULL; + int mask=NPY_ARRAY_OWNDATA; mask=~mask; elt0C->flags&=mask; PyObject *deepestObj=elt0; PyObject *base=elt0C->base; if(base) deepestObj=base; + bool isSpetialCase(false); while(base) { if(PyArray_Check(base)) { PyArrayObject *baseC=reinterpret_cast(base); - eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning; + eltOwning=(PyArray_FLAGS(baseC) & NPY_ARRAY_OWNDATA)?baseC:eltOwning; baseC->flags&=mask; base=baseC->base; if(base) deepestObj=base; } else - break; + { + isSpetialCase=true; + break; + } + } + if(isSpetialCase) + {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested. + std::size_t nbOfElems(sz0*sz1); + T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems); + std::copy(reinterpret_cast(data),reinterpret_cast(data)+nbOfElems,dataCpy); + ret->useArray(dataCpy,true,ParaMEDMEM::C_DEALLOC,sz0,sz1); + return ret.retn(); } typename ParaMEDMEM::MemArray& mma=ret->accessToMemArray(); if(eltOwning==NULL) @@ -363,7 +375,7 @@ int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj) /* If this array owns its own data, stop collapsing */ - if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) { + if (PyArray_CHKFLAGS(obj_arr, NPY_ARRAY_OWNDATA )) { break; } @@ -1043,6 +1055,69 @@ static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std:: throw INTERP_KERNEL::Exception(msg); } +static bool fillIntVector(PyObject *pyLi, std::vector& vec) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + vec.resize(sz); + for(int i=0;i >& arr) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !"; + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + arr.resize(sz); + for(int i=0;i > >& arr) throw(INTERP_KERNEL::Exception) { const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";