Documentation for extending NumPy leads to clang compiler failure
See original GitHub issueConsider the following example:
https://docs.scipy.org/doc/numpy-1.14.0/user/c-info.how-to-extend.html#required-subroutine
PyMODINIT_FUNC
init{name}(void)
{
(void)Py_InitModule({name}, mymethods);
import_array();
}
In Python 3, the initialization function returns a pointer to the module object, which means the return type of the initialization object is a pointer. The problem comes when clang expands the import_array()
macro and finds that it attempts to return a type that is an integer (I assume) rather than a pointer:
error: non-void function 'PyInit__module' should return a value [-Wreturn-type]
import_array();
^
/site-packages/numpy/core/include/numpy/__multiarray_api.h:1713:144: note: expanded from macro 'import_array'
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Clang Language Extensions - LLVM releases
This document describes the language extensions provided by Clang. In addition to the language extensions listed here, Clang aims to support a broad...
Read more >RuntimeError: Broken toolchain: cannot link a simple C ...
I was able to do this on alpine with only gcc g++ make python3-dev for numpy/nmslib. The cause of this particular issue seems...
Read more >Building from source — NumPy v1.24 Manual
These tests are skipped if the compiler is not auto-detected. Note that NumPy is developed mainly using GNU compilers and tested on MSVC...
Read more >NumPy 1.22.0 Release Notes
Clang defaults to non-IEEE and C99 conform behaviour otherwise. ... LoongArch is a new instruction set, numpy compilation failure on LoongArch architecture, ...
Read more >NumPy 1.21.0 Release Notes
There are unresolved problems compiling NumPy 1.20.0 with gcc-11.1. ... due to the fact that np.array(None) is already an object array.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Or call
_import_array()
, which allows you more control than justreturn
ingOkay, so the issue occurs only on py2 + py3c (the initialization function is nonstandard, and has py3 semantics). Solution appears to be to use import_array1