Skip to content

Commit ddbfa2c

Browse files
authored
Add --with-assertions configure flag to enable C assertions(#1731)
Defaults to 'no', but as before assertions are implied by --with-pydebug.
1 parent 0c4aca5 commit ddbfa2c

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ Documentation
11001100
Build
11011101
-----
11021102

1103+
- bpo-29941: Add ``--with-assertions`` configure flag to explicitly enable
1104+
C ``assert()`` checks. Defaults to off. ``--with-pydebug`` implies
1105+
``--with-assertions``.
1106+
11031107
- bpo-28787: Fix out-of-tree builds of Python when configured with
11041108
``--with--dtrace``.
11051109

configure

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ with_suffix
817817
enable_shared
818818
enable_profiling
819819
with_pydebug
820+
with_assertions
820821
enable_optimizations
821822
with_lto
822823
with_hash_algorithm
@@ -1512,6 +1513,7 @@ Optional Packages:
15121513
compiler
15131514
--with-suffix=.exe set executable suffix
15141515
--with-pydebug build with Py_DEBUG defined
1516+
--with-assertions build with C assertions enabled
15151517
--with-lto Enable Link Time Optimization in PGO builds.
15161518
Disabled by default.
15171519
--with-hash-algorithm=[fnv|siphash24]
@@ -6464,6 +6466,33 @@ $as_echo "no" >&6; }
64646466
fi
64656467

64666468

6469+
# Check for --with-assertions. Py_DEBUG implies assertions, but also changes
6470+
# the ABI. This allows enabling assertions without changing the ABI.
6471+
assertions='false'
6472+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-assertions" >&5
6473+
$as_echo_n "checking for --with-assertions... " >&6; }
6474+
6475+
# Check whether --with-assertions was given.
6476+
if test "${with_assertions+set}" = set; then :
6477+
withval=$with_assertions;
6478+
if test "$withval" != no
6479+
then
6480+
assertions='true'
6481+
fi
6482+
fi
6483+
6484+
if test "$assertions" = 'true'; then
6485+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6486+
$as_echo "yes" >&6; }
6487+
elif test "$Py_DEBUG" = 'true'; then
6488+
assertions='true'
6489+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: implied by --with-pydebug" >&5
6490+
$as_echo "implied by --with-pydebug" >&6; }
6491+
else
6492+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6493+
$as_echo "no" >&6; }
6494+
fi
6495+
64676496
# Enable optimization flags
64686497

64696498

@@ -7414,7 +7443,7 @@ case "$CC" in
74147443
;;
74157444
esac
74167445

7417-
if test "$Py_DEBUG" = 'true'; then
7446+
if test "$assertions" = 'true'; then
74187447
:
74197448
else
74207449
OPT="-DNDEBUG $OPT"

configure.ac

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,27 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
12511251
fi],
12521252
[AC_MSG_RESULT(no)])
12531253

1254+
# Check for --with-assertions. Py_DEBUG implies assertions, but also changes
1255+
# the ABI. This allows enabling assertions without changing the ABI.
1256+
assertions='false'
1257+
AC_MSG_CHECKING(for --with-assertions)
1258+
AC_ARG_WITH(assertions,
1259+
AC_HELP_STRING([--with-assertions], [build with C assertions enabled]),
1260+
[
1261+
if test "$withval" != no
1262+
then
1263+
assertions='true'
1264+
fi],
1265+
[])
1266+
if test "$assertions" = 'true'; then
1267+
AC_MSG_RESULT(yes)
1268+
elif test "$Py_DEBUG" = 'true'; then
1269+
assertions='true'
1270+
AC_MSG_RESULT(implied by --with-pydebug)
1271+
else
1272+
AC_MSG_RESULT(no)
1273+
fi
1274+
12541275
# Enable optimization flags
12551276
AC_SUBST(DEF_MAKE_ALL_RULE)
12561277
AC_SUBST(DEF_MAKE_RULE)
@@ -1868,7 +1889,7 @@ case "$CC" in
18681889
;;
18691890
esac
18701891

1871-
if test "$Py_DEBUG" = 'true'; then
1892+
if test "$assertions" = 'true'; then
18721893
:
18731894
else
18741895
OPT="-DNDEBUG $OPT"

0 commit comments

Comments
 (0)