-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
BUG: Avoid compilation error of wrapper file generated with SWIG >= 4.4 #30128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
|
As mentioned in the issue, we don't really hit this code in our tests (which is why we missed it in the first place). Could you suggest a meson-based small code sample that uses SWIG? Then we can try to incorporate this into the Using Python as glue guide, and make it run in C to test it for bitrot. |
|
The example idea can be in a separate PR if you wish, this one should be good to go. |
My knowledge of meson is virtually nonexistent. Could you direct me to a relevant example in the NumPy source code that could serve as a template for the proposed SWIG test? |
|
Thanks @rlaboiss . Let's get this in and leave an example test for another PR. |
|
Thanks for merging the PR. I just noticed that the bug can be triggered in NumPy's current source, with SWIG 4.4. installed in the system $ swig --version | grep Version
SWIG Version 4.4.0
$ cd tools/swig/test/
$ make
swig -c++ -python Array.i
swig -c++ -python Farray.i
swig -c++ -python Vector.i
swig -c++ -python Matrix.i
swig -c++ -python Tensor.i
swig -c++ -python Fortran.i
swig -c++ -python Flat.i
./setup.py build_ext -i
Array_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Array_wrap.cxx:8533:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
8533 | import_array();
| ^~~~~~~~~~~~
Farray_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Farray_wrap.cxx:6485:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
6485 | import_array();
| ^~~~~~~~~~~~
Vector_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Vector_wrap.cxx:9405:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
9405 | import_array();
| ^~~~~~~~~~~~
Matrix_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Matrix_wrap.cxx:9028:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
9028 | import_array();
| ^~~~~~~~~~~~
Tensor_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Tensor_wrap.cxx:9112:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
9112 | import_array();
| ^~~~~~~~~~~~
Fortran_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Fortran_wrap.cxx:5414:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
5414 | import_array();
| ^~~~~~~~~~~~
Flat_wrap.cxx: In function ‘int SWIG_mod_exec(PyObject*)’:
Flat_wrap.cxx:5088:3: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
5088 | import_array();
| ^~~~~~~~~~~~ |
….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
BUG: Avoid compilation error of wrapper file generated with SWIG >= 4.4 (#30128)
….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
….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
The
import_arraymacro, which is defined in the filenumpy/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 toint. 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
NULLor0, depending on the SWIG version being used (< 4.4 or >= 4.4, respectively). This change has been successfully tested against SWIG versions 4.3 and 4.4.Closes: #30122