diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/SConscript | 19 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarrayobject.h | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/numpyconfig.h.in | 1 | ||||
-rw-r--r-- | numpy/core/scons_support.py | 22 | ||||
-rw-r--r-- | numpy/core/setup.py | 14 | ||||
-rw-r--r-- | numpy/distutils/command/autodist.py | 14 | ||||
-rw-r--r-- | numpy/distutils/command/config.py | 6 |
7 files changed, 70 insertions, 8 deletions
diff --git a/numpy/core/SConscript b/numpy/core/SConscript index 662a06f54..caa27507c 100644 --- a/numpy/core/SConscript +++ b/numpy/core/SConscript @@ -1,4 +1,4 @@ -# Last Change: Fri Apr 24 08:00 PM 2009 J +# Last Change: Sun Apr 26 05:00 PM 2009 J # vim:syntax=python import os import sys @@ -13,10 +13,10 @@ from numscons import write_info from scons_support import CheckBrokenMathlib, define_no_smp, \ check_mlib, check_mlibs, is_npy_no_signal, CheckInline from scons_support import array_api_gen_bld, ufunc_api_gen_bld, template_bld, \ - umath_bld + umath_bld, CheckGCC4 from setup_common import * -ENABLE_SEPARATE_COMPILATION = False +ENABLE_SEPARATE_COMPILATION = True env = GetNumpyEnvironment(ARGUMENTS) env.Append(CPPPATH = env["PYEXTCPPPATH"]) @@ -30,7 +30,8 @@ if os.name == 'nt': # Starting Configuration #======================= config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib, - 'CheckCBLAS' : CheckCBLAS, 'CheckInline': CheckInline}, config_h = pjoin('config.h')) + 'CheckCBLAS' : CheckCBLAS, 'CheckInline': CheckInline, 'CheckGCC4' : CheckGCC4}, + config_h = pjoin('config.h')) # numpyconfig_sym will keep the values of some configuration variables, the one # needed for the public numpy API. @@ -189,6 +190,16 @@ numpyconfig_sym.append(('NPY_INLINE', inline)) if ENABLE_SEPARATE_COMPILATION: config.Define("ENABLE_SEPARATE_COMPILATION", 1) numpyconfig_sym.append(('NPY_ENABLE_SEPARATE_COMPILATION', 1)) + +# Checking for visibility macro +def visibility_define(): + if config.CheckGCC4(): + return '__attribute__((visibility("hidden")))' + else: + return '' + +numpyconfig_sym.append(('VISIBILITY_HIDDEN', visibility_define())) + #------------------------------------------------------- # Define the function PyOS_ascii_strod if not available #------------------------------------------------------- diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index 8a5c6560f..74a5834da 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -18,7 +18,7 @@ extern "C" CONFUSE_EMACS #include "numpyconfig.h" #ifdef NPY_ENABLE_SEPARATE_COMPILATION - #define NPY_NO_EXPORT __attribute__((visibility("hidden"))) + #define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN #else #define NPY_NO_EXPORT static #endif diff --git a/numpy/core/include/numpy/numpyconfig.h.in b/numpy/core/include/numpy/numpyconfig.h.in index 721266ba1..c976b4400 100644 --- a/numpy/core/include/numpy/numpyconfig.h.in +++ b/numpy/core/include/numpy/numpyconfig.h.in @@ -22,6 +22,7 @@ #define NPY_INLINE @NPY_INLINE@ #define NPY_ENABLE_SEPARATE_COMPILATION @NPY_ENABLE_SEPARATE_COMPILATION@ +#define NPY_VISIBILITY_HIDDEN @VISIBILITY_HIDDEN@ #define NPY_USE_C99_FORMATS @USE_C99_FORMATS@ diff --git a/numpy/core/scons_support.py b/numpy/core/scons_support.py index ceee5fafe..d1a2172c9 100644 --- a/numpy/core/scons_support.py +++ b/numpy/core/scons_support.py @@ -1,4 +1,4 @@ -#! Last Change: Fri Mar 13 01:00 PM 2009 J +#! Last Change: Sun Apr 26 05:00 PM 2009 J """Code to support special facilities to scons which are only useful for numpy.core, hence not put into numpy.distutils.scons""" @@ -97,6 +97,26 @@ def generate_umath_emitter(target, source, env): #----------------------------------------- # Other functions related to configuration #----------------------------------------- +def CheckGCC4(context): + src = """ +int +main() +{ +#if !(defined __GNUC__ && (__GNUC__ >= 4)) +die from an horrible death +#endif +} +""" + + context.Message("Checking if compiled with gcc 4.x or above ... ") + st = context.TryCompile(src, '.c') + + if st: + context.Result(' yes') + else: + context.Result(' no') + return st == 1 + def CheckBrokenMathlib(context, mathlib): src = """ /* check whether libm is broken */ diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 9d4f2c1a7..a32035cae 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -9,7 +9,7 @@ from distutils.sysconfig import get_config_var from setup_common import * # Set to True to enable multiple file compilations (experimental) -ENABLE_SEPARATE_COMPILATION = False +ENABLE_SEPARATE_COMPILATION = True # XXX: ugly, we use a class to avoid calling twice some expensive functions in # config.h/numpyconfig.h. I don't see a better way because distutils force @@ -264,6 +264,14 @@ def check_mathlib(config_cmd): "MATHLIB env variable") return mathlibs +def visibility_define(config): + """Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty + string).""" + if config.check_compiler_gcc4(): + return '__attribute__((visibility("hidden")))' + else: + return '' + 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 @@ -406,6 +414,10 @@ def configuration(parent_package='',top_path=None): # Inline check inline = config_cmd.check_inline() + # visibility check + hidden_visibility = visibility_define(config_cmd) + moredefs.append(('NPY_VISIBILITY_HIDDEN', hidden_visibility)) + # Add moredefs to header target_f = open(target,'a') for d in moredefs: diff --git a/numpy/distutils/command/autodist.py b/numpy/distutils/command/autodist.py index f246eb9f9..fe40119ef 100644 --- a/numpy/distutils/command/autodist.py +++ b/numpy/distutils/command/autodist.py @@ -23,3 +23,17 @@ static %(inline)s int static_func (void) return kw return '' + +def check_compiler_gcc4(cmd): + """Return True if the C compiler is GCC 4.x.""" + cmd._check_compiler() + body = """ +int +main() +{ +#ifndef __GNUC__ && (__GNUC__ >= 4) +die in an horrible death +#endif +} +""" + return cmd.try_compile(body, None, None) diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py index 67e4030a7..00821d260 100644 --- a/numpy/distutils/command/config.py +++ b/numpy/distutils/command/config.py @@ -15,7 +15,7 @@ from distutils.ccompiler import CompileError, LinkError import distutils from numpy.distutils.exec_command import exec_command from numpy.distutils.mingw32ccompiler import generate_manifest -from numpy.distutils.command.autodist import check_inline +from numpy.distutils.command.autodist import check_inline, check_compiler_gcc4 LANG_EXT['f77'] = '.f' LANG_EXT['f90'] = '.f90' @@ -346,6 +346,10 @@ int main () otherwise.""" return check_inline(self) + def check_compiler_gcc4(self): + """Return True if the C compiler is gcc >= 4.""" + return check_compiler_gcc4(self) + def get_output(self, body, headers=None, include_dirs=None, libraries=None, library_dirs=None, lang="c"): |