[SciPy-dev] Illegal instruction in ndimage test

David Cournapeau david@ar.media.kyoto-u.ac...
Thu Oct 18 19:43:51 CDT 2007

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 ?



More information about the Scipy-dev mailing list