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

Skip to content

Commit 5a0ab02

Browse files
committed
BUG: core: use #if check instead of #ifdef in checking HAVE_DECL_ISFINITE (ticket #1625)
Python #defines HAVE_DECL_ISFINITE 0 when the function is not available, so the proper check to do is #if.
1 parent 8b0d659 commit 5a0ab02

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

numpy/core/setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ def _add_decl(f):
215215
_macros = ["isnan", "isinf", "signbit", "isfinite"]
216216
if sys.version_info[:2] >= (2, 6):
217217
for f in _macros:
218-
already_declared = config.check_decl(fname2def("decl_%s" % f),
218+
py_symbol = fname2def("decl_%s" % f)
219+
already_declared = config.check_decl(py_symbol,
219220
headers=["Python.h", "math.h"])
220221
if already_declared:
221-
pub.append('NPY_%s' % fname2def("decl_%s" % f))
222+
if config.check_macro_true(py_symbol,
223+
headers=["Python.h", "math.h"]):
224+
pub.append('NPY_%s' % fname2def("decl_%s" % f))
222225
else:
223226
macros.append(f)
224227
else:

numpy/distutils/command/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ def check_decl(self, symbol,
169169

170170
return self.try_compile(body, headers, include_dirs)
171171

172+
def check_macro_true(self, symbol,
173+
headers=None, include_dirs=None):
174+
self._check_compiler()
175+
body = """
176+
int main()
177+
{
178+
#if %s
179+
#else
180+
#error false or undefined macro
181+
#endif
182+
;
183+
return 0;
184+
}""" % (symbol,)
185+
186+
return self.try_compile(body, headers, include_dirs)
187+
172188
def check_type(self, type_name, headers=None, include_dirs=None,
173189
library_dirs=None):
174190
"""Check type availability. Return True if the type can be compiled,

0 commit comments

Comments
 (0)