diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2008-02-09 00:45:11 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2008-02-09 00:45:11 +0000 |
commit | fbc211df7a2ebd27efe45cf4f943e21f5ad9b104 (patch) | |
tree | 9cea7049a873c0cd38bda75a5a5fe8d2d401b4fd /numpy/core/setup.py | |
parent | a2df3f7818deaf51d08b8bd9095e05d1011b46a5 (diff) | |
parent | d42ab1598a44cb00bffcc907605013eca012dbf9 (diff) | |
download | numpy-fbc211df7a2ebd27efe45cf4f943e21f5ad9b104.tar.gz |
Merge maskedarray branch up to r4776.
Diffstat (limited to 'numpy/core/setup.py')
-rw-r--r-- | numpy/core/setup.py | 176 |
1 files changed, 150 insertions, 26 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py index a8fd46911..e68d3137c 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -18,6 +18,36 @@ FUNCTIONS_TO_CHECK = [ ('rint', 'HAVE_RINT'), ] +def is_npy_no_signal(): + """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration + header.""" + return sys.platform == 'win32' + +def is_npy_no_smp(): + """Return True if the NPY_NO_SMP symbol must be defined in public + header (when SMP support cannot be reliably enabled).""" + # Python 2.3 causes a segfault when + # trying to re-acquire the thread-state + # which is done in error-handling + # ufunc code. NPY_ALLOW_C_API and friends + # cause the segfault. So, we disable threading + # for now. + if sys.version[:5] < '2.4.2': + nosmp = 1 + else: + # Perhaps a fancier check is in order here. + # so that threads are only enabled if there + # are actually multiple CPUS? -- but + # threaded code can be nice even on a single + # CPU so that long-calculating code doesn't + # block. + try: + nosmp = os.environ['NPY_NOSMP'] + nosmp = 1 + except KeyError: + nosmp = 0 + return nosmp == 1 + def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration,dot_join from numpy.distutils.system_info import get_info, default_lib_dirs @@ -53,28 +83,7 @@ def configuration(parent_package='',top_path=None): raise SystemError,"Failed to test configuration. "\ "See previous error messages for more information." - # Python 2.3 causes a segfault when - # trying to re-acquire the thread-state - # which is done in error-handling - # ufunc code. NPY_ALLOW_C_API and friends - # cause the segfault. So, we disable threading - # for now. - if sys.version[:5] < '2.4.2': - nosmp = 1 - else: - # Perhaps a fancier check is in order here. - # so that threads are only enabled if there - # are actually multiple CPUS? -- but - # threaded code can be nice even on a single - # CPU so that long-calculating code doesn't - # block. - try: - nosmp = os.environ['NPY_NOSMP'] - nosmp = 1 - except KeyError: - nosmp = 0 - if nosmp: moredefs = [('NPY_ALLOW_THREADS', '0')] - else: moredefs = [] + moredefs = [] # mathlibs = [] tc = testcode_mathlib() @@ -102,8 +111,8 @@ def configuration(parent_package='',top_path=None): if check_func(func_name): moredefs.append(defsymbol) - if sys.platform == 'win32': - moredefs.append('NPY_NO_SIGNAL') + if is_npy_no_signal(): + moredefs.append('__NPY_PRIVATE_NO_SIGNAL') if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture @@ -123,8 +132,6 @@ def configuration(parent_package='',top_path=None): target_f.write('#define %s\n' % (d)) else: target_f.write('#define %s %s\n' % (d[0],d[1])) - if not nosmp: # default is to use WITH_THREAD - target_f.write('#ifdef WITH_THREAD\n#define NPY_ALLOW_THREADS 1\n#else\n#define NPY_ALLOW_THREADS 0\n#endif\n') target_f.close() print 'File:',target target_f = open(target) @@ -151,6 +158,40 @@ def configuration(parent_package='',top_path=None): config.add_data_files((header_dir,target)) return target + def generate_numpyconfig_h(ext, build_dir): + """Depends on config.h: generate_config_h has to be called before !""" + target = join(build_dir,'numpyconfig.h') + if newer(__file__,target): + config_cmd = config.get_config_cmd() + log.info('Generating %s',target) + testcode = generate_numpyconfig_code(target) + + from distutils import sysconfig + python_include = sysconfig.get_python_inc() + python_h = join(python_include, 'Python.h') + if not os.path.isfile(python_h): + raise SystemError,\ + "Non-existing %s. Perhaps you need to install"\ + " python-dev|python-devel." % (python_h) + + config.numpy_include_dirs + result = config_cmd.try_run(testcode, + include_dirs = [python_include] + \ + config.numpy_include_dirs, + library_dirs = default_lib_dirs) + + if not result: + raise SystemError,"Failed to generate numpy configuration. "\ + "See previous error messages for more information." + + print 'File: %s' % target + target_f = open(target) + print target_f.read() + target_f.close() + print 'EOF' + config.add_data_files((header_dir, target)) + return target + def generate_api_func(module_name): def generate_api(ext, build_dir): script = join(codegen_dir, module_name + '.py') @@ -205,6 +246,7 @@ def configuration(parent_package='',top_path=None): config.add_extension('multiarray', sources = [join('src','multiarraymodule.c'), generate_config_h, + generate_numpyconfig_h, generate_array_api, join('src','scalartypes.inc.src'), join('src','arraytypes.inc.src'), @@ -216,6 +258,7 @@ def configuration(parent_package='',top_path=None): config.add_extension('umath', sources = [generate_config_h, + generate_numpyconfig_h, join('src','umathmodule.c.src'), generate_umath_c, generate_ufunc_api, @@ -231,6 +274,7 @@ def configuration(parent_package='',top_path=None): config.add_extension('_sort', sources=[join('src','_sortmodule.c.src'), generate_config_h, + generate_numpyconfig_h, generate_array_api, ], ) @@ -238,6 +282,7 @@ def configuration(parent_package='',top_path=None): config.add_extension('scalarmath', sources=[join('src','scalarmathmodule.c.src'), generate_config_h, + generate_numpyconfig_h, generate_array_api, generate_ufunc_api], ) @@ -342,6 +387,85 @@ int main(int argc, char **argv) testcode = '\n'.join(testcode) return testcode +def generate_numpyconfig_code(target): + """Return the source code as a string of the code to generate the + numpyconfig header file.""" + if sys.platform == 'win32': + target = target.replace('\\','\\\\') + # Config symbols to prepend + prepends = [('NPY_SIZEOF_SHORT', 'SIZEOF_SHORT'), + ('NPY_SIZEOF_INT', 'SIZEOF_INT'), + ('NPY_SIZEOF_LONG', 'SIZEOF_LONG'), + ('NPY_SIZEOF_FLOAT', 'SIZEOF_FLOAT'), + ('NPY_SIZEOF_DOUBLE', 'SIZEOF_DOUBLE'), + ('NPY_SIZEOF_LONGDOUBLE', 'SIZEOF_LONG_DOUBLE'), + ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T')] + + testcode = [""" +#include <Python.h> +#include "config.h" + +int main() +{ + FILE* f; + + f = fopen("%s", "w"); + if (f == NULL) { + return -1; + } +""" % target] + + testcode.append(r""" + fprintf(f, "/*\n * This file is generated by %s. DO NOT EDIT \n */\n"); +""" % __file__) + + # Prepend NPY_ to any SIZEOF defines + testcode.extend([r' fprintf(f, "#define ' + i + r' %%d \n", %s);' % j for i, j in prepends]) + + # Conditionally define NPY_NO_SIGNAL + if is_npy_no_signal(): + testcode.append(r' fprintf(f, "\n#define NPY_NO_SIGNAL\n");') + + # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot + # support thread support reliably + if is_npy_no_smp(): + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 1\n");') + else: + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 0\n");') + + tmpcode = r""" + #ifdef PY_LONG_LONG + fprintf(f, "\n#define %s %%d \n", %s); + fprintf(f, "#define %s %%d \n", %s); + #else + fprintf(f, "/* PY_LONG_LONG not defined */ \n"); + #endif""" + testcode.append(tmpcode % ('NPY_SIZEOF_LONGLONG', 'SIZEOF_LONG_LONG', + 'NPY_SIZEOF_PY_LONG_LONG', 'SIZEOF_PY_LONG_LONG')) + + testcode.append(r""" +#ifndef CHAR_BIT + { + unsigned char var = 2; + int i = 0; + while (var >= 2) { + var = var << 1; + i++; + } + fprintf(f,"#define CHAR_BIT %d\n", i+1); + } +#else + fprintf(f, "/* #define CHAR_BIT %d */\n", CHAR_BIT); +#endif""") + + testcode.append(""" + fclose(f); + + return 0; +} +""") + return "\n".join(testcode) + if __name__=='__main__': from numpy.distutils.core import setup setup(configuration=configuration) |