question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation for extending NumPy leads to clang compiler failure

See original GitHub issue

Consider 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
eric-wiesercommented, Jan 27, 2018

Or call _import_array(), which allows you more control than just returning

3reactions
ghostcommented, Jan 27, 2018

Okay, 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found