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

Skip to content

Commit f76f109

Browse files
committed
Avoid checking twice the IEEE macros.
1 parent 18091e7 commit f76f109

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

numpy/core/setup.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class CallOnceOnly(object):
2222
def __init__(self):
2323
self._check_types = None
24+
self._check_ieee_macros = None
2425

2526
def check_types(self, *a, **kw):
2627
if self._check_types is None:
@@ -30,6 +31,14 @@ def check_types(self, *a, **kw):
3031
out = copy.deepcopy(_pik.loads(self._check_types))
3132
return out
3233

34+
def check_ieee_macros(self, *a, **kw):
35+
if self._check_ieee_macros is None:
36+
out = check_ieee_macros(*a, **kw)
37+
self._check_ieee_macros = _pik.dumps(out)
38+
else:
39+
out = copy.deepcopy(_pik.loads(self._check_ieee_macros))
40+
return out
41+
3342
def pythonlib_dir():
3443
"""return path where libpython* is."""
3544
if sys.platform == 'win32':
@@ -147,6 +156,13 @@ def check_funcs(funcs_name):
147156
fns = [f + prec for f in c99_funcs]
148157
check_funcs(fns)
149158

159+
def fname2def(name):
160+
return "HAVE_%s" % name.upper()
161+
162+
def check_ieee_macros(config):
163+
priv = []
164+
pub = []
165+
150166
# Normally, isnan and isinf are macro (C99), but some platforms only have
151167
# func, or both func and macro version. Check for macro only, and define
152168
# replacement ones if not found.
@@ -155,10 +171,10 @@ def check_funcs(funcs_name):
155171
for f in ["isnan", "isinf", "signbit", "isfinite"]:
156172
st = config.check_decl(f, headers = ["Python.h", "math.h"])
157173
if st:
158-
moredefs.append(fname2def("decl_%s" % f))
174+
priv.append(fname2def("decl_%s" % f))
175+
pub.append('NPY_%s' % fname2def("decl_%s" % f))
159176

160-
def fname2def(name):
161-
return "HAVE_%s" % name.upper()
177+
return priv, pub
162178

163179
def check_types(config_cmd, ext, build_dir):
164180
private_defines = []
@@ -271,6 +287,7 @@ def generate_config_h(ext, build_dir):
271287
moredefs.append(('MATHLIB',','.join(mathlibs)))
272288

273289
check_math_capabilities(config_cmd, moredefs, mathlibs)
290+
moredefs.extend(cocache.check_ieee_macros(config_cmd)[0])
274291

275292
# Signal check
276293
if is_npy_no_signal():
@@ -338,17 +355,7 @@ def generate_numpyconfig_h(ext, build_dir):
338355
else:
339356
moredefs.append(('NPY_NO_SMP', 0))
340357

341-
# Normally, isnan and isinf are macro (C99), but some platforms
342-
# only have func, or both func and macro version. Check for macro
343-
# only, and define replacement ones if not found.
344-
# Note: including Python.h is necessary because it modifies some
345-
# math.h definitions
346-
# XXX: we check those twice... should decouple tests from
347-
# config.h/numpyconfig.h to avoid this
348-
for f in ["isnan", "isinf", "signbit", "isfinite"]:
349-
st = config_cmd.check_decl(f, headers = ["Python.h", "math.h"])
350-
if st:
351-
moredefs.append('NPY_HAVE_DECL_%s' % f.upper())
358+
moredefs.extend(cocache.check_ieee_macros(config_cmd)[1])
352359

353360
# Check wether we can use inttypes (C99) formats
354361
if config_cmd.check_decl('PRIdPTR', headers = ['inttypes.h']):

0 commit comments

Comments
 (0)