Thanks to visit codestin.com
Credit goes to github.com

Skip to content

f2py bug on OpenBSD "'threads.h': file not found " #19437

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

Closed
dimpase opened this issue Jul 8, 2021 · 13 comments · Fixed by #20881
Closed

f2py bug on OpenBSD "'threads.h': file not found " #19437

dimpase opened this issue Jul 8, 2021 · 13 comments · Fixed by #20881

Comments

@dimpase
Copy link
Contributor

dimpase commented Jul 8, 2021

Reproducing:

Build NumPy 1.20.3 on OpenBSD using its usual compiler, clang 10.0.1, and (e)gfortran.
The resulting NumPy's f2py is buggy. It fails the test in #18179, and also builds of SciPy using it are
broken, see scipy/scipy#14364

Error message:

here is Python3 and numpy used/built:

$ python3
Python 3.8.8 (default, Apr 19 2021, 10:23:47) 
[Clang 10.0.1 ] on openbsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, numpy; print(numpy.__version__, sys.version)
1.20.3 3.8.8 (default, Apr 19 2021, 10:23:47) 
[Clang 10.0.1 ]

which, while running

pytest -sv numpy/f2py/tests/test_callback.py -k 'test_all[t]' -r s -x

give

E                                  /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c:83:10: fatal error: 'threads.h' file not found
E                                  #include <threads.h>
E                                           ^~~~~~~~~~~
E                                  1 warning and 1 error generated.

full log:

$ pytest -sv numpy/f2py/tests/test_callback.py -k 'test_all[t]' -r s -x
================================================================================================================================== test session starts ===================================================================================================================================
platform openbsd6 -- Python 3.8.8, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /home/dima/sagetrac-mirror/local/bin/python3
cachedir: .pytest_cache
hypothesis profile 'np.test() profile' -> database=None, deadline=None, print_blob=True, derandomize=True, suppress_health_check=[HealthCheck.data_too_large, HealthCheck.filter_too_much, HealthCheck.too_slow, HealthCheck.return_value, HealthCheck.large_base_example, HealthCheck.not_a_test_method, HealthCheck.function_scoped_fixture]
rootdir: /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/f2py
plugins: hypothesis-6.14.1
collected 16 items / 14 deselected / 2 selected                                                                                                                                                                                                                                          

numpy/f2py/tests/test_callback.py::TestF77Callback::test_all[t] ERROR

========================================================================================================================================= ERRORS =========================================================================================================================================
_____________________________________________________________________________________________________________________ ERROR at setup of TestF77Callback.test_all[t] ______________________________________________________________________________________________________________________

self = <numpy.f2py.tests.test_callback.TestF77Callback object at 0x7245f658340>

    def setup(self):
        if sys.platform == 'win32':
            pytest.skip('Fails with MinGW64 Gfortran (Issue #9673)')
    
        if self.module is not None:
            return
    
        # Check compiler availability first
        if not has_c_compiler():
            pytest.skip("No C compiler available")
    
        codes = []
        if self.sources:
            codes.extend(self.sources)
        if self.code is not None:
            codes.append(self.suffix)
    
        needs_f77 = False
        needs_f90 = False
        for fn in codes:
            if fn.endswith('.f'):
                needs_f77 = True
            elif fn.endswith('.f90'):
                needs_f90 = True
        if needs_f77 and not has_f77_compiler():
            pytest.skip("No Fortran 77 compiler available")
        if needs_f90 and not has_f90_compiler():
            pytest.skip("No Fortran 90 compiler available")
    
        # Build the module
        if self.code is not None:
>           self.module = build_code(self.code, options=self.options,
                                     skip=self.skip, only=self.only,
                                     suffix=self.suffix,
                                     module_name=self.module_name)

numpy/f2py/tests/util.py:351: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
numpy/f2py/tests/util.py:73: in wrapper
    memo[key] = func(*a, **kw)
numpy/f2py/tests/util.py:158: in build_code
    return build_module([path], options=options, skip=skip, only=only,
numpy/f2py/tests/util.py:73: in wrapper
    memo[key] = func(*a, **kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

source_files = ['/tmp/tmp1lfeb71d.f'], options = [], skip = [], only = [], module_name = '_test_ext_module_5403'

    @_memoize
    def build_module(source_files, options=[], skip=[], only=[], module_name=None):
        """
        Compile and import a f2py module, built from the given files.
    
        """
    
        code = ("import sys; sys.path = %s; import numpy.f2py as f2py2e; "
                "f2py2e.main()" % repr(sys.path))
    
        d = get_module_dir()
    
        # Copy files
        dst_sources = []
        f2py_sources = []
        for fn in source_files:
            if not os.path.isfile(fn):
                raise RuntimeError("%s is not a file" % fn)
            dst = os.path.join(d, os.path.basename(fn))
            shutil.copyfile(fn, dst)
            dst_sources.append(dst)
    
            base, ext = os.path.splitext(dst)
            if ext in ('.f90', '.f', '.c', '.pyf'):
                f2py_sources.append(dst)
    
        # Prepare options
        if module_name is None:
            module_name = get_temp_module_name()
        f2py_opts = ['-c', '-m', module_name] + options + f2py_sources
        if skip:
            f2py_opts += ['skip:'] + skip
        if only:
            f2py_opts += ['only:'] + only
    
        # Build
        cwd = os.getcwd()
        try:
            os.chdir(d)
            cmd = [sys.executable, '-c', code] + f2py_opts
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
            out, err = p.communicate()
            if p.returncode != 0:
>               raise RuntimeError("Running f2py failed: %s\n%s"
                                   % (cmd[4:], asstr(out)))
E                                  RuntimeError: Running f2py failed: ['-m', '_test_ext_module_5403', '/tmp/tmp0yy230c6/tmp1lfeb71d.f']
E                                  running build
E                                  running config_cc
E                                  unifing config_cc, config, build_clib, build_ext, build commands --compiler options
E                                  running config_fc
E                                  unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
E                                  running build_src
E                                  build_src
E                                  building extension "_test_ext_module_5403" sources
E                                  f2py options: []
E                                  f2py:> /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c
E                                  creating /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8
E                                  Reading fortran codes...
E                                  	Reading file '/tmp/tmp0yy230c6/tmp1lfeb71d.f' (format:fix,strict)
E                                  Line #22 in /tmp/tmp0yy230c6/tmp1lfeb71d.f:"       intent(callback) fun"
E                                  	analyzeline: missing __user__ module (could be nothing)
E                                  Line #22 in /tmp/tmp0yy230c6/tmp1lfeb71d.f:"       intent(callback) fun"
E                                  	analyzeline: appending intent(callback) fun to t2 arguments
E                                  Line #52 in /tmp/tmp0yy230c6/tmp1lfeb71d.f:"       intent(callback, hide) global_f"
E                                  	analyzeline: missing __user__ module (could be nothing)
E                                  Line #52 in /tmp/tmp0yy230c6/tmp1lfeb71d.f:"       intent(callback, hide) global_f"
E                                  	analyzeline: appending intent(callback) global_f to hidden_callback arguments
E                                  Post-processing...
E                                  	Block: _test_ext_module_5403
E                                  			Block: t
E                                  					Block: fun
E                                  			Block: func
E                                  			Block: func0
E                                  			Block: t2
E                                  					Block: fun
E                                  			Block: string_callback
E                                  					Block: callback
E                                  			Block: string_callback_array
E                                  					Block: callback
E                                  			Block: hidden_callback
E                                  					Block: global_f
E                                  			Block: hidden_callback2
E                                  Post-processing (stage 2)...
E                                  Building modules...
E                                  	Constructing call-back function "cb_fun_in_t__user__routines"
E                                  	  def fun(): return a
E                                  	Constructing call-back function "cb_fun_in_t2__user__routines"
E                                  	  def fun(): return a
E                                  	Constructing call-back function "cb_callback_in_string_callback__user__routines"
E                                  	  def callback(r): return a
E                                  	Constructing call-back function "cb_callback_in_string_callback_array__user__routines"
E                                  	  def callback(cu,[lencu]): return a
E                                  	Constructing call-back function "cb_global_f_in_hidden_callback__user__routines"
E                                  	  def global_f(a): return r
E                                  	Building module "_test_ext_module_5403"...
E                                  		Constructing wrapper function "t"...
E                                  		  a = t(fun,[fun_extra_args])
E                                  		Constructing wrapper function "func"...
E                                  		  a = func(a)
E                                  		Constructing wrapper function "func0"...
E                                  		  a = func0()
E                                  		Constructing wrapper function "t2"...
E                                  		  a = t2(fun,[fun_extra_args])
E                                  		Constructing wrapper function "string_callback"...
E                                  		  a = string_callback(callback,[callback_extra_args])
E                                  		Constructing wrapper function "string_callback_array"...
E                                  		  a = string_callback_array(callback,cu,[lencu,callback_extra_args])
E                                  		Constructing wrapper function "hidden_callback"...
E                                  		  r = hidden_callback(a)
E                                  		Constructing wrapper function "hidden_callback2"...
E                                  		  r = hidden_callback2(a)
E                                  	Wrote C/API module "_test_ext_module_5403" to file "/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c"
E                                    adding '/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/fortranobject.c' to sources.
E                                    adding '/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8' to include_dirs.
E                                  copying /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8
E                                  copying /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8
E                                  build_src: building npy-pkg config files
E                                  running build_ext
E                                  customize UnixCCompiler
E                                  customize UnixCCompiler using build_ext
E                                  get_default_fcompiler: matching types: '['gnu', 'gnu95']'
E                                  customize GnuFCompiler
E                                  Found executable /usr/local/bin/egfortran
E                                  gnu: no Fortran 90 compiler found
E                                  Found executable /usr/bin/ld
E                                  Found executable /usr/bin/ar
E                                  Found executable /usr/bin/ranlib
E                                  gnu: no Fortran 90 compiler found
E                                  customize Gnu95FCompiler
E                                  customize Gnu95FCompiler
E                                  customize Gnu95FCompiler using build_ext
E                                  building '_test_ext_module_5403' extension
E                                  compiling C sources
E                                  C compiler: clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -g -fPIC -O2 -pipe -g -O2 -pipe -g -I/usr/local/include -I/usr/local/include -fPIC
E                                  
E                                  creating /tmp/tmpvdb1a4dd/tmp
E                                  creating /tmp/tmpvdb1a4dd/tmp/tmpvdb1a4dd
E                                  creating /tmp/tmpvdb1a4dd/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8
E                                  compile options: '-DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8 -I/home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include -I/home/dima/sagetrac-mirror/local/include -I/usr/local/include/python3.8 -c'
E                                  clang: /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c
E                                  In file included from /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c:16:
E                                  In file included from /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/fortranobject.h:13:
E                                  In file included from /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4:
E                                  In file included from /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12:
E                                  In file included from /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1944:
E                                  /home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: "Using deprecated NumPy API, disable it with "          "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
E                                  #warning "Using deprecated NumPy API, disable it with " \
E                                   ^
E                                  /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c:83:10: fatal error: 'threads.h' file not found
E                                  #include <threads.h>
E                                           ^~~~~~~~~~~
E                                  1 warning and 1 error generated.
E                                  appenddecl: "intent" not implemented.
E                                  analyzevars: character array "character*8 cu(lencu)" is considered as "character cu(lencu,8)"; "intent(c)" is forced.
E                                  analyzevars: character array "character*8 cu(lencu)" is considered as "character cu(lencu,8)"; "intent(c)" is forced.
E                                  appenddecl: "intent" not implemented.
E                                  appenddecl: "intent" not implemented.
E                                  append_needs: unknown need 'int'
E                                  append_needs: unknown need 'int'
E                                  append_needs: unknown need 'int'
E                                  append_needs: unknown need 'int'
E                                  error: Command "clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -O2 -pipe -g -fPIC -O2 -pipe -g -O2 -pipe -g -I/usr/local/include -I/usr/local/include -fPIC -DNPY_DISABLE_OPTIMIZATION=1 -I/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8 -I/home/dima/sagetrac-mirror/local/lib/python3.8/site-packages/numpy/core/include -I/home/dima/sagetrac-mirror/local/include -I/usr/local/include/python3.8 -c /tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.c -o /tmp/tmpvdb1a4dd/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.o -MMD -MF /tmp/tmpvdb1a4dd/tmp/tmpvdb1a4dd/src.openbsd-6.9-amd64-3.8/_test_ext_module_5403module.o.d" failed with exit status 1

numpy/f2py/tests/util.py:133: RuntimeError
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================================ 14 deselected, 1 error in 6.35s =============================================================================================================================

C compiler info:

__STDC_NO_THREADS__ is undefined and there is no header:

$ cc -v                                                                                                                                                                                                                              
OpenBSD clang version 10.0.1 
Target: amd64-unknown-openbsd6.9
Thread model: posix
InstalledDir: /usr/bin
$ cat t.c
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
int main() {return 1;}
$ cc -c t.c
t.c:2:10: fatal error: 'threads.h' file not found
#include <threads.h>
         ^~~~~~~~~~~
1 error generated.
@pearu
Copy link
Contributor

pearu commented Jul 9, 2021

The underlying issue is explained in

numpy/numpy/f2py/cfuncs.py

Lines 573 to 581 in b32b72e

#elif defined(__STDC_VERSION__) \\
&& (__STDC_VERSION__ >= 201112L) \\
&& !defined(__STDC_NO_THREADS__) \\
&& (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12))
/* __STDC_NO_THREADS__ was first defined in a maintenance release of glibc 2.12,
see https://lists.gnu.org/archive/html/commit-hurd/2012-07/msg00180.html,
so `!defined(__STDC_NO_THREADS__)` may give false positive for the existence
of `threads.h` when using an older release of glibc 2.12 */
#include <threads.h>

So, to resolve this issue, we'll need to refine the algorithm for defining F2PY_THREAD_LOCAL_DECL in the same file.

An option is to enable F2PY_USE_PYTHON_TLS define for OpenBSD so that inclusion of threads.h becomes conditionally unnecessary..

@dimpase
Copy link
Contributor Author

dimpase commented Jul 9, 2021

as far as I know, OpenBSD doesn't use glibc, so that's a totally different story.

@pearu
Copy link
Contributor

pearu commented Jul 9, 2021

as far as I know, OpenBSD doesn't use glibc, so that's a totally different story.

Sure (notice the !defined(__GLIBC__) subexpression). What is the different story?

A workaround would be to use __has_include CPP macro that is available in clang but it would be better to have a more strict test for detecting STDC THREADS rather than assuming that underlying system is not broken.

@pearu
Copy link
Contributor

pearu commented Jul 9, 2021

We have NPY_OS_BSD from https://github.com/numpy/numpy/blob/main/numpy/core/include/numpy/npy_os.h. So, a possible fix is to include the following line to the elif-block shown above:

&& !defined(NPY_OS_BSD) \\

@dimpase
Copy link
Contributor Author

dimpase commented Jul 19, 2021

@thierry-FreeBSD - what's the state of affairs on FreeBSD here? It does have threads.h, isn't it?
So one has to use something like NPY_OS_OPENBSD, not NPY_OS_BSD, right?

@thierry-FreeBSD
Copy link

@dimpase Indeed, on FreeBSD it is located at /usr/include/threads.h .

@dimpase
Copy link
Contributor Author

dimpase commented Jul 19, 2021

The test above passes if I add

&& !defined(__OpenBSD__) \\

rather than && !defined(NPY_OS_OPENBSD) \\ - this seems to indicate that for some reason numpy/npy_os.h does not get
included.

@dimpase
Copy link
Contributor Author

dimpase commented Sep 13, 2021

I'm told there is a clang bug affecting OpenBSD:

On 9/3/2021 9:02 PM, Brad Smith wrote:
> On 7/8/2021 5:57 AM, Dima Pasechnik wrote:
>> This seems to violate C11 standard (see
>> https://en.cppreference.com/w/c/thread), which says
>> "If the macro constant __STDC_NO_THREADS__(C11) is defined by the
>> compiler,
>>  the header <threads.h> and all of the names listed here are not
>> provided."
>> and leads to various issues such as
>> https://github.com/numpy/numpy/issues/18179
>>
>> The clang/llvm project appears to deal with this on per platform basis.
>> I am not sure whether this is an OpenBSD bug, or the upstream Clang=
>> bug, though.

> The symbol should be defined by the compiler. I am just about to commit
> a diff upstream to Clang to fix this for OpenBSD.

https://github.com/llvm/llvm-project/commit/d8cd7806310c51af912a647a6ca46de62ff13214

made a typo.


https://github.com/llvm/llvm-project/commit/bce178a5ecf10df762cbda59c7f60cca8e52ce3a

I am seeing about it being backported to the 13 branch.

@sandeep-gh
Copy link

I can reproduce this issue for numpy 1.21.4 on openbsd built using gfortran. What could be a resolution/workaround for this?

@dimpase
Copy link
Contributor Author

dimpase commented Nov 27, 2021 via email

rgommers added a commit to rgommers/numpy that referenced this issue Jan 23, 2022
Closes rgommers/scipy#125
This is a follow-up of numpygh-18910 (included in 1.20.3 and 1.21.0), which
looks incorrect.

This fixes warnings like these when building SciPy with Mingw-w64:
```
[94/1557] Compiling C object scipy/linalg/_flapack.cp39-win_amd64.pyd.p/meson-generated_..__flapackmodule.c.obj
In file included from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:12,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\f2py\src/fortranobject.h:13,
                 from scipy/linalg/_flapackmodule.c:16:
scipy/linalg/_flapackmodule.c:1248:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1248 | static F2PY_THREAD_LOCAL_DECL cb_cselect_in_gees__user__routines_t *_active_cb_cselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1410:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1410 | static F2PY_THREAD_LOCAL_DECL cb_zselect_in_gees__user__routines_t *_active_cb_zselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1572:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1572 | static F2PY_THREAD_LOCAL_DECL cb_sselect_in_gees__user__routines_t *_active_cb_sselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1738:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1738 | static F2PY_THREAD_LOCAL_DECL cb_dselect_in_gees__user__routines_t *_active_cb_dselect_in_gees__user__routines = NULL;
      | ^~~~~~

...
```

Also fixes numpygh-19437, where `__STDC_NO_THREADS__` should be defined but
isn't (this seems to be more common, e.g. one can reports for ICC about
this).
@rgommers
Copy link
Member

@dimpase see the PR linked just above this comment, I included your fix.

That should be backported to 1.22.2, but not anymore to 1.21.x - you can define __STDC_NO_THREADS__, or define F2PY_THREAD_LOCAL_DECL to whatever you need as a workaround.

rgommers added a commit to rgommers/numpy that referenced this issue Jan 23, 2022
Closes rgommers/scipy#125
This is a follow-up of numpygh-18910 (included in 1.20.3 and 1.21.0), which
looks incorrect.

This fixes warnings like these when building SciPy with Mingw-w64:
```
[94/1557] Compiling C object scipy/linalg/_flapack.cp39-win_amd64.pyd.p/meson-generated_..__flapackmodule.c.obj
In file included from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:12,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\f2py\src/fortranobject.h:13,
                 from scipy/linalg/_flapackmodule.c:16:
scipy/linalg/_flapackmodule.c:1248:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1248 | static F2PY_THREAD_LOCAL_DECL cb_cselect_in_gees__user__routines_t *_active_cb_cselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1410:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1410 | static F2PY_THREAD_LOCAL_DECL cb_zselect_in_gees__user__routines_t *_active_cb_zselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1572:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1572 | static F2PY_THREAD_LOCAL_DECL cb_sselect_in_gees__user__routines_t *_active_cb_sselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1738:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1738 | static F2PY_THREAD_LOCAL_DECL cb_dselect_in_gees__user__routines_t *_active_cb_dselect_in_gees__user__routines = NULL;
      | ^~~~~~

...
```

Also fixes numpygh-19437, where `__STDC_NO_THREADS__` should be defined but
isn't (this seems to be more common, e.g. one can reports for ICC about
this).
charris pushed a commit to charris/numpy that referenced this issue Jan 27, 2022
Closes rgommers/scipy#125
This is a follow-up of numpygh-18910 (included in 1.20.3 and 1.21.0), which
looks incorrect.

This fixes warnings like these when building SciPy with Mingw-w64:
```
[94/1557] Compiling C object scipy/linalg/_flapack.cp39-win_amd64.pyd.p/meson-generated_..__flapackmodule.c.obj
In file included from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:12,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                 from C:\hostedtoolcache\windows\Python\3.9.9\x64\lib\site-packages\numpy\f2py\src/fortranobject.h:13,
                 from scipy/linalg/_flapackmodule.c:16:
scipy/linalg/_flapackmodule.c:1248:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1248 | static F2PY_THREAD_LOCAL_DECL cb_cselect_in_gees__user__routines_t *_active_cb_cselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1410:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1410 | static F2PY_THREAD_LOCAL_DECL cb_zselect_in_gees__user__routines_t *_active_cb_zselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1572:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1572 | static F2PY_THREAD_LOCAL_DECL cb_sselect_in_gees__user__routines_t *_active_cb_sselect_in_gees__user__routines = NULL;
      | ^~~~~~
scipy/linalg/_flapackmodule.c:1738:1: warning: 'thread' attribute directive ignored [-Wattributes]
 1738 | static F2PY_THREAD_LOCAL_DECL cb_dselect_in_gees__user__routines_t *_active_cb_dselect_in_gees__user__routines = NULL;
      | ^~~~~~

...
```

Also fixes numpygh-19437, where `__STDC_NO_THREADS__` should be defined but
isn't (this seems to be more common, e.g. one can reports for ICC about
this).
@dimpase
Copy link
Contributor Author

dimpase commented Dec 14, 2022

OK, I can confirm all is good on OpenBSD 7.2 and numpy 1.23, thanks again.

@barracuda156
Copy link

MacOS may not have threads.h either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants