Skip to content

Commit 8f161c4

Browse files
committed
BLD: fix incorrect feature checks for mandatory math functions
Should fix the build on FreeBSD and other OSes that are not C99-compliant. Closes numpygh-24873
1 parent 9d4c148 commit 8f161c4

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

‎numpy/core/meson.build‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,32 @@ endforeach
148148
# Mandatory functions: if not found, fail the build
149149
# Some of these can still be blocklisted if the C99 implementation
150150
# is buggy, see numpy/core/src/common/npy_config.h
151-
mandatory_funcs = [
151+
mandatory_math_funcs = [
152152
'sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs',
153153
'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin',
154154
'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp',
155155
'expm1', 'log1p', 'acosh', 'asinh', 'atanh',
156-
'rint', 'trunc', 'exp2',
157-
'copysign', 'nextafter', 'strtoll', 'strtoull', 'cbrt',
156+
'rint', 'trunc', 'exp2', 'copysign', 'nextafter', 'cbrt',
158157
'log2', 'pow', 'hypot', 'atan2',
159-
'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh',
160-
'creal', 'cimag', 'conj'
161158
]
162-
foreach func: mandatory_funcs
163-
if not cc.has_function(func)
164-
error('Function `{func}` not found')
159+
foreach func: mandatory_math_funcs
160+
if not cc.has_function(func, prefix: '#include <math.h>', dependencies: m_dep)
161+
error(f'Function `@func@` not found')
162+
endif
163+
endforeach
164+
165+
mandatory_complex_math_funcs = [
166+
'csin', 'csinh', 'ccos', 'ccosh', 'ctan', 'ctanh', 'creal', 'cimag', 'conj'
167+
]
168+
foreach func: mandatory_complex_math_funcs
169+
if not cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep)
170+
error(f'Function `@func@` not found')
171+
endif
172+
endforeach
173+
174+
foreach func: ['strtoll', 'strtoull']
175+
if not cc.has_function(func, prefix: '#include <stdlib.h>')
176+
error(f'Function `@func@` not found')
165177
endif
166178
endforeach
167179

@@ -175,13 +187,13 @@ c99_complex_funcs = [
175187
foreach func: c99_complex_funcs
176188
func_single = func + 'f'
177189
func_longdouble = func + 'l'
178-
if cc.has_function(func)
190+
if cc.has_function(func, prefix: '#include <complex.h>', dependencies: m_dep)
179191
cdata.set10('HAVE_' + func.to_upper(), true)
180192
endif
181-
if cc.has_function(func_single)
193+
if cc.has_function(func_single, prefix: '#include <complex.h>', dependencies: m_dep)
182194
cdata.set10('HAVE_' + func_single.to_upper(), true)
183195
endif
184-
if cc.has_function(func_longdouble)
196+
if cc.has_function(func_longdouble, prefix: '#include <complex.h>', dependencies: m_dep)
185197
cdata.set10('HAVE_' + func_longdouble.to_upper(), true)
186198
endif
187199
endforeach
@@ -190,7 +202,7 @@ endforeach
190202
# libnpymath as a C99 compat layer, these may still be relevant.
191203
c99_macros = ['isfinite', 'isinf', 'isnan', 'signbit']
192204
foreach macro: c99_macros
193-
if cc.has_function(macro)
205+
if cc.has_function(macro, prefix: '#include <math.h>', dependencies: m_dep)
194206
cdata.set10('NPY_HAVE_DECL_' + macro.to_upper(), true)
195207
if not cc.has_header_symbol('Python.h', macro, dependencies: py_dep)
196208
# Add in config.h as well, except if it will clash with Python's config.h content

0 commit comments

Comments
 (0)