X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingDataArrayTraits.hxx;h=9d0ae2a520a937f5373179416b438057a9517e62;hb=662a2a2393a25baef77e42f74204b11b70a9646c;hp=c22b758dcae67bcff12be988a39cb4623aff0bac;hpb=805f6b27aae3dd3a5e683bb40ab07b5cacf37f20;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx b/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx index c22b758dc..9d0ae2a52 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -34,14 +34,16 @@ #endif #endif +#ifdef WITH_NUMPY // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it. -// if no more alive the "standart" DataArray deallocator is called. +// if no more alive the "standard" DataArray deallocator is called. void numarrdeal(void *pt, void *wron) { void **wronc=(void **)wron; PyObject *weakRefOnOwner=reinterpret_cast(wronc[0]); PyObject *obj=PyWeakref_GetObject(weakRefOnOwner); + int64_t *offset=reinterpret_cast(wronc[2]); if(obj!=Py_None) { Py_XINCREF(obj); @@ -54,11 +56,13 @@ void numarrdeal(void *pt, void *wron) { typedef void (*MyDeallocator)(void *,void *); MyDeallocator deall=(MyDeallocator)wronc[1]; - deall(pt,NULL); + deall(pt,offset); Py_XDECREF(weakRefOnOwner); } + delete offset; delete [] wronc; } +#endif template struct PyCallBackDataArraySt { @@ -67,7 +71,8 @@ struct PyCallBackDataArraySt { }; typedef struct PyCallBackDataArraySt PyCallBackDataArrayChar; -typedef struct PyCallBackDataArraySt PyCallBackDataArrayInt; +typedef struct PyCallBackDataArraySt PyCallBackDataArrayInt32; +typedef struct PyCallBackDataArraySt PyCallBackDataArrayInt64; typedef struct PyCallBackDataArraySt PyCallBackDataArrayFloat; typedef struct PyCallBackDataArraySt PyCallBackDataArrayDouble; @@ -81,9 +86,15 @@ extern "C" return (PyObject *)self; } - static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs) + static PyObject *callbackmcdataarrayint32___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs) { - PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) ); + PyCallBackDataArrayInt32 *self = (PyCallBackDataArrayInt32 *) ( type->tp_alloc(type, 0) ); + return (PyObject *)self; + } + + static PyObject *callbackmcdataarrayint64___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs) + { + PyCallBackDataArrayInt64 *self = (PyCallBackDataArrayInt64 *) ( type->tp_alloc(type, 0) ); return (PyObject *)self; } @@ -120,7 +131,7 @@ extern "C" // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed. // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients. - static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw) + static PyObject *callbackmcdataarrayint32_call(PyCallBackDataArrayInt32 *self, PyObject *args, PyObject *kw) { if(self->_pt_mc) { @@ -131,6 +142,19 @@ extern "C" return Py_None; } + // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed. + // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients. + static PyObject *callbackmcdataarrayint64_call(PyCallBackDataArrayInt64 *self, PyObject *args, PyObject *kw) + { + if(self->_pt_mc) + { + MEDCoupling::MemArray& mma=self->_pt_mc->accessToMemArray(); + mma.destroy(); + } + Py_XINCREF(Py_None); + return Py_None; + } + // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed. // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients. static PyObject *callbackmcdataarrayfloat_call(PyCallBackDataArrayFloat *self, PyObject *args, PyObject *kw) @@ -201,10 +225,53 @@ PyTypeObject PyCallBackDataArrayChar_RefType = { }; -PyTypeObject PyCallBackDataArrayInt_RefType = { +PyTypeObject PyCallBackDataArrayInt32_RefType = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "callbackmcdataarrayint32", + sizeof(PyCallBackDataArrayInt32), + 0, + callbackmcdataarray_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + (ternaryfunc)callbackmcdataarrayint32_call, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + callbackmcdataarray___init__, /*tp_init*/ + PyType_GenericAlloc, /*tp_alloc*/ + callbackmcdataarrayint32___new__, /*tp_new*/ + PyObject_GC_Del, /*tp_free*/ +}; + + +PyTypeObject PyCallBackDataArrayInt64_RefType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "callbackmcdataarrayint", - sizeof(PyCallBackDataArrayInt), + "callbackmcdataarrayint64", + sizeof(PyCallBackDataArrayInt64), 0, callbackmcdataarray_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ @@ -216,7 +283,7 @@ PyTypeObject PyCallBackDataArrayInt_RefType = { 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ - (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/ + (ternaryfunc)callbackmcdataarrayint64_call, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ @@ -239,7 +306,7 @@ PyTypeObject PyCallBackDataArrayInt_RefType = { 0, /*tp_dictoffset*/ callbackmcdataarray___init__, /*tp_init*/ PyType_GenericAlloc, /*tp_alloc*/ - callbackmcdataarrayint___new__, /*tp_new*/ + callbackmcdataarrayint64___new__, /*tp_new*/ PyObject_GC_Del, /*tp_free*/ }; @@ -327,6 +394,7 @@ PyTypeObject PyCallBackDataArrayDouble_RefType = { PyObject_GC_Del, /*tp_free*/ }; +#ifdef WITH_NUMPY template struct NPYTraits { @@ -348,4 +416,21 @@ struct NPYTraits static PyObject *Array_SWIGTYPE; }; +template<> +struct NPYTraits +{ + static const int NPYObjectType=NPY_INT32; + static PyTypeObject *NPYFunc; + static PyObject *Array_SWIGTYPE; +}; + +template<> +struct NPYTraits +{ + static const int NPYObjectType=NPY_INT64; + static PyTypeObject *NPYFunc; + static PyObject *Array_SWIGTYPE; +}; +#endif + #endif