Skip to content

Commit 1e424da

Browse files
authored
BUG: Avoid compilation error of wrapper file generated with SWIG >= 4.4 (numpy#30128)
The `import_array` macro, which is defined in the file `numpy/core/code_generators/generate_numpy_api.py`, is intended for use inside an internal SWIG function that is called in the generated C wrapper file. This macro contains a return statement whose argument must match the function definition. Until version 4.3 of SWIG, the aforementioned function returned a `void*` value. However, in version 4.4, the return value was changed to `int`. This causes compilation of code using import_array() to fail with the following error message: `returning 'void *' from a function with return type 'int' makes integer from pointer without a cast [-Wint-conversion].` This commit resolves the issue by returning either `NULL` or `0`, depending on the SWIG version being used (< 3.4 or >= 3.4, respectively). This change has been successfully tested against SWIG versions 4.3 and 4.4. Closes: numpy#30122
1 parent a8546b7 commit 1e424da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

numpy/_core/code_generators/generate_numpy_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@
157157
return 0;
158158
}
159159
160+
#if (SWIG_VERSION < 0x040400)
161+
#define _RETURN_VALUE NULL
162+
#else
163+
#define _RETURN_VALUE 0
164+
#endif
165+
160166
#define import_array() { \
161167
if (_import_array() < 0) { \
162168
PyErr_Print(); \
163169
PyErr_SetString( \
164170
PyExc_ImportError, \
165171
"numpy._core.multiarray failed to import" \
166172
); \
167-
return NULL; \
173+
return _RETURN_VALUE; \
168174
} \
169175
}
170176

0 commit comments

Comments
 (0)