Skip to content

Conversation

@charris
Copy link
Member

@charris charris commented Nov 3, 2025

Backport of #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: #30122

….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
@charris charris added this to the 2.3.5 release milestone Nov 3, 2025
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Nov 3, 2025
@charris charris merged commit 073cf79 into numpy:maintenance/2.3.x Nov 3, 2025
75 checks passed
@charris charris deleted the backport-30128 branch November 3, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants