[Numpy-discussion] Request code review of numpy.i changes
Egor Zindy
ezindy at gmail.com
Tue Mar 12 09:27:24 EDT 2013
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 at 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 at sandia.gov **
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: numpy.i
Type: application/octet-stream
Size: 97352 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130312/c85b554b/attachment.obj>
More information about the NumPy-Discussion
mailing list