Skip to content

Commit 60d0410

Browse files
nehebjpakkane
authored andcommitted
test 64-bit types for atomic
The check is currently broken as atomic_flag_clear is a macro, not a function. Change it to test linkage instead. Also test if atomics work with 64-bit types. On certain platforms like MIPS, external libatomic is needed. Signed-off-by: Rosen Penev <[email protected]>
1 parent 1e6986b commit 60d0410

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎mesonbuild/dependencies/misc.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,24 @@ def netcdf_factory(env: 'Environment',
5656
class AtomicBuiltinDependency(BuiltinDependency):
5757
def __init__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any]):
5858
super().__init__(name, env, kwargs)
59-
self.feature_since = ('1.7.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
59+
self.feature_since = ('1.7.0', "consider checking for `atomic_fetch_add` of a 64-bit type with and without `find_library('atomic')`")
6060

61-
if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>', env)[0]:
62-
self.is_found = True
61+
code = '''#include <stdatomic.h>\n\nint main() {\n atomic_int_least64_t a;\n return atomic_fetch_add(&b, 1);\n}''' # [ignore encoding] this is C, not python, Mr. Lint
62+
63+
self.is_found = bool(self.clib_compiler.links(code, env)[0])
6364

6465

6566
class AtomicSystemDependency(SystemDependency):
6667
def __init__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any]):
6768
super().__init__(name, env, kwargs)
68-
self.feature_since = ('1.7.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
69+
self.feature_since = ('1.7.0', "consider checking for `atomic_fetch_add` of a 64-bit type with and without `find_library('atomic')`")
6970

7071
h = self.clib_compiler.has_header('stdatomic.h', '', env)
71-
self.link_args = self.clib_compiler.find_library('atomic', env, [], self.libtype)
72+
if not h[0]:
73+
return
7274

73-
if h[0] and self.link_args:
74-
self.is_found = True
75+
self.link_args = self.clib_compiler.find_library('atomic', env, [], self.libtype)
76+
self.is_found = bool(self.link_args)
7577

7678

7779
class DlBuiltinDependency(BuiltinDependency):

0 commit comments

Comments
 (0)