Request code review of numpy.i changes

https://github.com/wfspotz/numpy/compare/numpy-swig
** Bill Spotz ** ** Sandia National Laboratories Voice: (505)845-0170 ** ** P.O. Box 5800 Fax: (505)284-0154 ** ** Albuquerque, NM 87185-0370 Email: wfspotz@sandia.gov **

Thanks Bill,
I wasn't happy with my use of either PyCObject_FromVoidPtr or PyArray_BASE. Both are now deprecated.
So I updated all the ARGOUTVIEWM_ definitions with
%#ifdef SWIGPY_USE_CAPSULE PyObject* cap = PyCapsule_New((void*)(*$1), SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); %#else PyObject* cap = PyCObject_FromVoidPtr((void*)(*$1), SWIG_Python_DestroyModule); %#endif
%#if NPY_API_VERSION < 0x00000007 PyArray_BASE(array) = cap; %#else PyArray_SetBaseObject(array,cap); %#endif
This could probably be improved with the use of a macro, and checking the returned value of PyArray_SetBaseObject wouldn't hurt either. Anyway, it's a start. Hopefully I haven't messed my use of either SWIGPY_CAPSULE_NAME or SWIG_Python_DestroyModule here.
Other changes I made relate to various warnings, in particular relating to the use of SWIG_Python_AppendOutput($result, XXX) where XXX should be a PyObject but was a PyArrayObject.
In ARGOUTVIEW / ARGOUTVIEWM typedefs, I made sure there was a
PyObject* obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); PyArrayObject* array = (PyArrayObject*) obj;
which allows me to then use (instead of ,array) $result = SWIG_Python_AppendOutput($result,obj);
In the other few other instances where this construct doesn't apply (ARGOUT_ARRAY1 for example) I used typecasting $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum);
I can't think of anything else at this stage.
Kind regards, Egor
On 12 March 2013 03:55, Bill Spotz wfspotz@sandia.gov wrote:
https://github.com/wfspotz/numpy/compare/numpy-swig
** Bill Spotz ** ** Sandia National Laboratories Voice: (505)845-0170 ** ** P.O. Box 5800 Fax: (505)284-0154 ** ** Albuquerque, NM 87185-0370 Email: wfspotz@sandia.gov **
participants (2)
-
Bill Spotz
-
Egor Zindy