Beichen Zhang Beichen Zhang - 10 days ago 8
Python Question

Numpy CAPI PyArray_New Visual Studio Warning C4055

I am converting a computational C program to Python with using PyArray_SimpleNew() to create a numpy array in C. However, i get warning

C4055:: from data pointer 'void *' to function pointer 'PyObject *(__cdecl *)


Here is an extraction of the relevant code:

PyObject* myArray=NULL;
npy_int nd=1;
npy_int dims[1]={10};
myArray=PyArray_SimpleNew(nd,dims,NPY_UINT64)


the warning happens at the last line. After some google searches, it suggests that it's due to an improper implementation in Numpy library that violates C standards.

So my questions are,

1.Could anyone explain what's happening here? Especially where that "void*" comes from?
2.Does this warning really matters in this use case? Would it be safe to suppress it?

some reference:

http://docs.scipy.org/doc/numpy/reference/c-api.array.html
Pointer-type mismatch with PyArray_SimpleNew

Answer

Okay So after some digging into Python's source code for PyArray_SimpleNew(), it seems python is using a nested Macro with a few function call-back behind the scene. Therefore what compiler see is a pointer to a function rather than a proper return value of type PyObject*.This is an non-standard uses and u can't do nothing but to suppress the warning manually