[SciPy-dev] Illegal instruction in ndimage test

Matthieu Brucher matthieu.brucher at gmail.com
Fri Oct 19 01:42:13 EDT 2007


This is not very different from the Numpy API interface. You have an array
of void* that contains your functions, and then you define macros that use
this array with a cast to get the real function. Here, it seems that there
is no array, but the result is identical (but it shouldn't redefine an
already defined function :|)

Matthieu

2007/10/19, David Cournapeau <david at ar.media.kyoto-u.ac.jp>:
>
> Matthew Brett wrote:
>
> >
> >
> > The problem seems to be this set of lines in nd_image.h (starting line
> > 276):
> >
> > #define NA_OutputArray (*(PyArrayObject* (*)
> > (PyObject*,NumarrayType,int) ) (void *) NA_OutputArray)
> > #define NA_IoArray (*(PyArrayObject* (*) (PyObject*,NumarrayType,int)
> > ) (void *) NA_IoArray)
> > #define NA_NewArray (*(PyArrayObject* (*) (void* buffer,
> > NumarrayType, int, ...) ) (void *) NA_NewArray )
> > #define NA_elements (*(unsigned long (*) (PyArrayObject*) ) (void *)
> > NA_elements)
> > #define NA_InputArray (*(PyArrayObject* (*)
> > (PyObject*,NumarrayType,int) ) (void *) NA_InputArray)
> >
> Wow, nice function pointers. I did not even know this syntax was valid.
> Redefines the functions with the define is a good obsfucation, too. As
> far as I understand, the line
>
> #define NA_NewArray (*(PyArrayObject* (*) (void* buffer, NumarrayType,
> int, ...) ) (void *) NA_NewArray )
>
> Means that the previously defined NA_NewArray functions has its output
> casted, output which is a function pointer. So basically, this is
> equivalent to
>
> #define NA_NewArray (*(func_ptr) (void *) NA_NewArray )
>
> with func_ptr a function pointer, function taking (void* buffer,
> NumarrayType, int, ...) as arguments, and returning PyArrayObject*. The
> first * is strange, though, I don't understand what than means (you
> cannot dereference a function pointer, normally ?).
>
> But anyway, the fact that the compiler says that it emits non supported
> opcodes may suggest that this is relying on undefined behaviour ?
>
> cheers,
>
> David
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20071019/ce9fe7a4/attachment.html>


More information about the SciPy-Dev mailing list