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

Skip to content

Commit 6ad5e7c

Browse files
committed
Do not harcode visibility macro, enable it for gcc 4.
1 parent 9d30995 commit 6ad5e7c

7 files changed

Lines changed: 70 additions & 8 deletions

File tree

numpy/core/SConscript

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Last Change: Fri Apr 24 08:00 PM 2009 J
1+
# Last Change: Sun Apr 26 05:00 PM 2009 J
22
# vim:syntax=python
33
import os
44
import sys
@@ -13,10 +13,10 @@ from numscons import write_info
1313
from scons_support import CheckBrokenMathlib, define_no_smp, \
1414
check_mlib, check_mlibs, is_npy_no_signal, CheckInline
1515
from scons_support import array_api_gen_bld, ufunc_api_gen_bld, template_bld, \
16-
umath_bld
16+
umath_bld, CheckGCC4
1717
from setup_common import *
1818

19-
ENABLE_SEPARATE_COMPILATION = False
19+
ENABLE_SEPARATE_COMPILATION = True
2020

2121
env = GetNumpyEnvironment(ARGUMENTS)
2222
env.Append(CPPPATH = env["PYEXTCPPPATH"])
@@ -30,7 +30,8 @@ if os.name == 'nt':
3030
# Starting Configuration
3131
#=======================
3232
config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib,
33-
'CheckCBLAS' : CheckCBLAS, 'CheckInline': CheckInline}, config_h = pjoin('config.h'))
33+
'CheckCBLAS' : CheckCBLAS, 'CheckInline': CheckInline, 'CheckGCC4' : CheckGCC4},
34+
config_h = pjoin('config.h'))
3435

3536
# numpyconfig_sym will keep the values of some configuration variables, the one
3637
# needed for the public numpy API.
@@ -189,6 +190,16 @@ numpyconfig_sym.append(('NPY_INLINE', inline))
189190
if ENABLE_SEPARATE_COMPILATION:
190191
config.Define("ENABLE_SEPARATE_COMPILATION", 1)
191192
numpyconfig_sym.append(('NPY_ENABLE_SEPARATE_COMPILATION', 1))
193+
194+
# Checking for visibility macro
195+
def visibility_define():
196+
if config.CheckGCC4():
197+
return '__attribute__((visibility("hidden")))'
198+
else:
199+
return ''
200+
201+
numpyconfig_sym.append(('VISIBILITY_HIDDEN', visibility_define()))
202+
192203
#-------------------------------------------------------
193204
# Define the function PyOS_ascii_strod if not available
194205
#-------------------------------------------------------

numpy/core/include/numpy/ndarrayobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" CONFUSE_EMACS
1818
#include "numpyconfig.h"
1919

2020
#ifdef NPY_ENABLE_SEPARATE_COMPILATION
21-
#define NPY_NO_EXPORT __attribute__((visibility("hidden")))
21+
#define NPY_NO_EXPORT NPY_VISIBILITY_HIDDEN
2222
#else
2323
#define NPY_NO_EXPORT static
2424
#endif

numpy/core/include/numpy/numpyconfig.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#define NPY_INLINE @NPY_INLINE@
2424
#define NPY_ENABLE_SEPARATE_COMPILATION @NPY_ENABLE_SEPARATE_COMPILATION@
25+
#define NPY_VISIBILITY_HIDDEN @VISIBILITY_HIDDEN@
2526

2627
#define NPY_USE_C99_FORMATS @USE_C99_FORMATS@
2728

numpy/core/scons_support.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! Last Change: Fri Mar 13 01:00 PM 2009 J
1+
#! Last Change: Sun Apr 26 05:00 PM 2009 J
22

33
"""Code to support special facilities to scons which are only useful for
44
numpy.core, hence not put into numpy.distutils.scons"""
@@ -97,6 +97,26 @@ def generate_umath_emitter(target, source, env):
9797
#-----------------------------------------
9898
# Other functions related to configuration
9999
#-----------------------------------------
100+
def CheckGCC4(context):
101+
src = """
102+
int
103+
main()
104+
{
105+
#if !(defined __GNUC__ && (__GNUC__ >= 4))
106+
die from an horrible death
107+
#endif
108+
}
109+
"""
110+
111+
context.Message("Checking if compiled with gcc 4.x or above ... ")
112+
st = context.TryCompile(src, '.c')
113+
114+
if st:
115+
context.Result(' yes')
116+
else:
117+
context.Result(' no')
118+
return st == 1
119+
100120
def CheckBrokenMathlib(context, mathlib):
101121
src = """
102122
/* check whether libm is broken */

numpy/core/setup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from setup_common import *
1010

1111
# Set to True to enable multiple file compilations (experimental)
12-
ENABLE_SEPARATE_COMPILATION = False
12+
ENABLE_SEPARATE_COMPILATION = True
1313

1414
# XXX: ugly, we use a class to avoid calling twice some expensive functions in
1515
# config.h/numpyconfig.h. I don't see a better way because distutils force
@@ -264,6 +264,14 @@ def check_mathlib(config_cmd):
264264
"MATHLIB env variable")
265265
return mathlibs
266266

267+
def visibility_define(config):
268+
"""Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty
269+
string)."""
270+
if config.check_compiler_gcc4():
271+
return '__attribute__((visibility("hidden")))'
272+
else:
273+
return ''
274+
267275
def configuration(parent_package='',top_path=None):
268276
from numpy.distutils.misc_util import Configuration,dot_join
269277
from numpy.distutils.system_info import get_info, default_lib_dirs
@@ -406,6 +414,10 @@ def generate_numpyconfig_h(ext, build_dir):
406414
# Inline check
407415
inline = config_cmd.check_inline()
408416

417+
# visibility check
418+
hidden_visibility = visibility_define(config_cmd)
419+
moredefs.append(('NPY_VISIBILITY_HIDDEN', hidden_visibility))
420+
409421
# Add moredefs to header
410422
target_f = open(target,'a')
411423
for d in moredefs:

numpy/distutils/command/autodist.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ def check_inline(cmd):
2323
return kw
2424

2525
return ''
26+
27+
def check_compiler_gcc4(cmd):
28+
"""Return True if the C compiler is GCC 4.x."""
29+
cmd._check_compiler()
30+
body = """
31+
int
32+
main()
33+
{
34+
#ifndef __GNUC__ && (__GNUC__ >= 4)
35+
die in an horrible death
36+
#endif
37+
}
38+
"""
39+
return cmd.try_compile(body, None, None)

numpy/distutils/command/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import distutils
1616
from numpy.distutils.exec_command import exec_command
1717
from numpy.distutils.mingw32ccompiler import generate_manifest
18-
from numpy.distutils.command.autodist import check_inline
18+
from numpy.distutils.command.autodist import check_inline, check_compiler_gcc4
1919

2020
LANG_EXT['f77'] = '.f'
2121
LANG_EXT['f90'] = '.f90'
@@ -346,6 +346,10 @@ def check_inline(self):
346346
otherwise."""
347347
return check_inline(self)
348348

349+
def check_compiler_gcc4(self):
350+
"""Return True if the C compiler is gcc >= 4."""
351+
return check_compiler_gcc4(self)
352+
349353
def get_output(self, body, headers=None, include_dirs=None,
350354
libraries=None, library_dirs=None,
351355
lang="c"):

0 commit comments

Comments
 (0)