Skip to content

Commit acb8c52

Browse files
committed
add -Werror=declaration-after-statement only to stdlib extension modules (closes #21121)
Patch from Stefan Krah.
1 parent 3b48af0 commit acb8c52

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

Makefile.pre.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,17 @@ OPT= @OPT@
7171
BASECFLAGS= @BASECFLAGS@
7272
BASECPPFLAGS= @BASECPPFLAGS@
7373
CONFIGURE_CFLAGS= @CFLAGS@
74+
# CFLAGS_NODIST is used for building the interpreter and stdlib C extensions.
75+
# Use it when a compiler flag should _not_ be part of the distutils CFLAGS
76+
# once Python is installed (Issue #21121).
77+
CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@
7478
CONFIGURE_CPPFLAGS= @CPPFLAGS@
7579
CONFIGURE_LDFLAGS= @LDFLAGS@
7680
# Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
7781
# command line to append to these values without stomping the pre-set
7882
# values.
7983
PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
84+
PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST)
8085
# Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
8186
# be able to build extension modules using the directories specified in the
8287
# environment variables
@@ -91,7 +96,7 @@ ARFLAGS= @ARFLAGS@
9196
# Extra C flags added for building the interpreter object files.
9297
CFLAGSFORSHARED=@CFLAGSFORSHARED@
9398
# C flags used for building the interpreter object files
94-
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
99+
PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
95100

96101

97102
# Machine-dependent subdirectories

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #21121: Don't force 3rd party C extensions to be built with
31+
-Werror=declaration-after-statement.
32+
3033
- Issue #21975: Fixed crash when using uninitialized sqlite3.Row (in particular
3134
when unpickling pickled sqlite3.Row). sqlite3.Row is now initialized in the
3235
__new__() method.

configure

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ SHLIB_SUFFIX
662662
LIBTOOL_CRUFT
663663
OTHER_LIBTOOL_OPT
664664
UNIVERSAL_ARCH_FLAGS
665+
CFLAGS_NODIST
665666
BASECFLAGS
666667
OPT
667668
ABIFLAGS
@@ -6292,6 +6293,7 @@ fi
62926293

62936294

62946295

6296+
62956297
# The -arch flags for universal builds on OSX
62966298
UNIVERSAL_ARCH_FLAGS=
62976299

@@ -6452,7 +6454,7 @@ $as_echo "$ac_cv_declaration_after_statement_warning" >&6; }
64526454

64536455
if test $ac_cv_declaration_after_statement_warning = yes
64546456
then
6455-
BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
6457+
CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
64566458
fi
64576459

64586460
# if using gcc on alpha, use -mieee to get (near) full IEEE 754

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ then
11381138
fi
11391139

11401140
AC_SUBST(BASECFLAGS)
1141+
AC_SUBST(CFLAGS_NODIST)
11411142

11421143
# The -arch flags for universal builds on OSX
11431144
UNIVERSAL_ARCH_FLAGS=
@@ -1222,7 +1223,7 @@ yes)
12221223

12231224
if test $ac_cv_declaration_after_statement_warning = yes
12241225
then
1225-
BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
1226+
CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
12261227
fi
12271228

12281229
# if using gcc on alpha, use -mieee to get (near) full IEEE 754

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
2121

22+
# Add special CFLAGS reserved for building the interpreter and the stdlib
23+
# modules (Issue #21121).
24+
cflags = sysconfig.get_config_var('CFLAGS')
25+
py_cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST')
26+
sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist
27+
2228
def get_platform():
2329
# cross build
2430
if "_PYTHON_HOST_PLATFORM" in os.environ:

0 commit comments

Comments
 (0)