Skip to content

Commit 17e831d

Browse files
macdicedutow
authored andcommitted
Assume that <stdbool.h> conforms to the C standard.
Previously we checked "for <stdbool.h> that conforms to C99" using autoconf's AC_HEADER_STDBOOL macro. We've required C99 since PostgreSQL 12, so the test was redundant, and under C23 it was broken: autoconf 2.69's implementation doesn't understand C23's new empty header (the macros it's looking for went away, replaced by language keywords). Later autoconf versions fixed that, but let's just remove the anachronistic test. HAVE_STDBOOL_H and HAVE__BOOL will no longer be defined, but they weren't directly tested in core or likely extensions (except in 11, see below). PG_USE_STDBOOL (or USE_STDBOOL in 11 and 12) is still defined when sizeof(bool) is 1, which should be true on all modern systems. Otherwise we define our own bool type and values of size 1, which would fail to compile under C23 as revealed by the broken test. (We'll probably clean that dead code up in master, but here we want a minimal back-patchable change.) This came to our attention when GCC 15 recently started using using C23 by default and failed to compile the replacement code, as reported by Sam James and build farm animal alligator. Back-patch to all supported releases, and then two older versions that also know about <stdbool.h>, per the recently-out-of-support policy[1]. 12 requires C99 so it's much like the supported releases, but 11 only assumes C89 so it now uses AC_CHECK_HEADERS instead of the overly picky AC_HEADER_STDBOOL. (I could find no discussion of which historical systems had <stdbool.h> but failed the conformance test; if they ever existed, they surely aren't relevant to that policy's goals.) [1] https://wiki.postgresql.org/wiki/Committing_checklist#Policies Reported-by: Sam James <sam@gentoo.org> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> (master version) Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> (approach) Discussion: https://www.postgresql.org/message-id/flat/87o72eo9iu.fsf%40gentoo.org
1 parent 4f0eaa1 commit 17e831d

File tree

5 files changed

+51
-161
lines changed

5 files changed

+51
-161
lines changed

configure

Lines changed: 43 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,116 +2101,116 @@ $as_echo "$ac_res" >&6; }
21012101

21022102
} # ac_fn_c_check_func
21032103

2104-
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2105-
# -------------------------------------------
2106-
# Tests whether TYPE exists after having included INCLUDES, setting cache
2107-
# variable VAR accordingly.
2108-
ac_fn_c_check_type ()
2104+
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2105+
# ----------------------------------------------------
2106+
# Tries to find if the field MEMBER exists in type AGGR, after including
2107+
# INCLUDES, setting cache variable VAR accordingly.
2108+
ac_fn_c_check_member ()
21092109
{
21102110
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2111-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2112-
$as_echo_n "checking for $2... " >&6; }
2113-
if eval \${$3+:} false; then :
2111+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2112+
$as_echo_n "checking for $2.$3... " >&6; }
2113+
if eval \${$4+:} false; then :
21142114
$as_echo_n "(cached) " >&6
21152115
else
2116-
eval "$3=no"
21172116
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21182117
/* end confdefs.h. */
2119-
$4
2118+
$5
21202119
int
21212120
main ()
21222121
{
2123-
if (sizeof ($2))
2124-
return 0;
2122+
static $2 ac_aggr;
2123+
if (ac_aggr.$3)
2124+
return 0;
21252125
;
21262126
return 0;
21272127
}
21282128
_ACEOF
21292129
if ac_fn_c_try_compile "$LINENO"; then :
2130+
eval "$4=yes"
2131+
else
21302132
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21312133
/* end confdefs.h. */
2132-
$4
2134+
$5
21332135
int
21342136
main ()
21352137
{
2136-
if (sizeof (($2)))
2137-
return 0;
2138+
static $2 ac_aggr;
2139+
if (sizeof ac_aggr.$3)
2140+
return 0;
21382141
;
21392142
return 0;
21402143
}
21412144
_ACEOF
21422145
if ac_fn_c_try_compile "$LINENO"; then :
2143-
2146+
eval "$4=yes"
21442147
else
2145-
eval "$3=yes"
2148+
eval "$4=no"
21462149
fi
21472150
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21482151
fi
21492152
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21502153
fi
2151-
eval ac_res=\$$3
2154+
eval ac_res=\$$4
21522155
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21532156
$as_echo "$ac_res" >&6; }
21542157
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21552158

2156-
} # ac_fn_c_check_type
2159+
} # ac_fn_c_check_member
21572160

2158-
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2159-
# ----------------------------------------------------
2160-
# Tries to find if the field MEMBER exists in type AGGR, after including
2161-
# INCLUDES, setting cache variable VAR accordingly.
2162-
ac_fn_c_check_member ()
2161+
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2162+
# -------------------------------------------
2163+
# Tests whether TYPE exists after having included INCLUDES, setting cache
2164+
# variable VAR accordingly.
2165+
ac_fn_c_check_type ()
21632166
{
21642167
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2165-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2166-
$as_echo_n "checking for $2.$3... " >&6; }
2167-
if eval \${$4+:} false; then :
2168+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2169+
$as_echo_n "checking for $2... " >&6; }
2170+
if eval \${$3+:} false; then :
21682171
$as_echo_n "(cached) " >&6
21692172
else
2173+
eval "$3=no"
21702174
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21712175
/* end confdefs.h. */
2172-
$5
2176+
$4
21732177
int
21742178
main ()
21752179
{
2176-
static $2 ac_aggr;
2177-
if (ac_aggr.$3)
2178-
return 0;
2180+
if (sizeof ($2))
2181+
return 0;
21792182
;
21802183
return 0;
21812184
}
21822185
_ACEOF
21832186
if ac_fn_c_try_compile "$LINENO"; then :
2184-
eval "$4=yes"
2185-
else
21862187
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21872188
/* end confdefs.h. */
2188-
$5
2189+
$4
21892190
int
21902191
main ()
21912192
{
2192-
static $2 ac_aggr;
2193-
if (sizeof ac_aggr.$3)
2194-
return 0;
2193+
if (sizeof (($2)))
2194+
return 0;
21952195
;
21962196
return 0;
21972197
}
21982198
_ACEOF
21992199
if ac_fn_c_try_compile "$LINENO"; then :
2200-
eval "$4=yes"
2200+
22012201
else
2202-
eval "$4=no"
2202+
eval "$3=yes"
22032203
fi
22042204
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
22052205
fi
22062206
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
22072207
fi
2208-
eval ac_res=\$$4
2208+
eval ac_res=\$$3
22092209
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
22102210
$as_echo "$ac_res" >&6; }
22112211
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
22122212

2213-
} # ac_fn_c_check_member
2213+
} # ac_fn_c_check_type
22142214

22152215
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
22162216
# --------------------------------------------
@@ -13483,100 +13483,6 @@ fi
1348313483
## Header files
1348413484
##
1348513485

13486-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
13487-
$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
13488-
if ${ac_cv_header_stdbool_h+:} false; then :
13489-
$as_echo_n "(cached) " >&6
13490-
else
13491-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13492-
/* end confdefs.h. */
13493-
13494-
#include <stdbool.h>
13495-
#ifndef bool
13496-
"error: bool is not defined"
13497-
#endif
13498-
#ifndef false
13499-
"error: false is not defined"
13500-
#endif
13501-
#if false
13502-
"error: false is not 0"
13503-
#endif
13504-
#ifndef true
13505-
"error: true is not defined"
13506-
#endif
13507-
#if true != 1
13508-
"error: true is not 1"
13509-
#endif
13510-
#ifndef __bool_true_false_are_defined
13511-
"error: __bool_true_false_are_defined is not defined"
13512-
#endif
13513-
13514-
struct s { _Bool s: 1; _Bool t; } s;
13515-
13516-
char a[true == 1 ? 1 : -1];
13517-
char b[false == 0 ? 1 : -1];
13518-
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
13519-
char d[(bool) 0.5 == true ? 1 : -1];
13520-
/* See body of main program for 'e'. */
13521-
char f[(_Bool) 0.0 == false ? 1 : -1];
13522-
char g[true];
13523-
char h[sizeof (_Bool)];
13524-
char i[sizeof s.t];
13525-
enum { j = false, k = true, l = false * true, m = true * 256 };
13526-
/* The following fails for
13527-
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
13528-
_Bool n[m];
13529-
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
13530-
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
13531-
/* Catch a bug in an HP-UX C compiler. See
13532-
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
13533-
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
13534-
*/
13535-
_Bool q = true;
13536-
_Bool *pq = &q;
13537-
13538-
int
13539-
main ()
13540-
{
13541-
13542-
bool e = &s;
13543-
*pq |= q;
13544-
*pq |= ! q;
13545-
/* Refer to every declared value, to avoid compiler optimizations. */
13546-
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
13547-
+ !m + !n + !o + !p + !q + !pq);
13548-
13549-
;
13550-
return 0;
13551-
}
13552-
_ACEOF
13553-
if ac_fn_c_try_compile "$LINENO"; then :
13554-
ac_cv_header_stdbool_h=yes
13555-
else
13556-
ac_cv_header_stdbool_h=no
13557-
fi
13558-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13559-
fi
13560-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5
13561-
$as_echo "$ac_cv_header_stdbool_h" >&6; }
13562-
ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default"
13563-
if test "x$ac_cv_type__Bool" = xyes; then :
13564-
13565-
cat >>confdefs.h <<_ACEOF
13566-
#define HAVE__BOOL 1
13567-
_ACEOF
13568-
13569-
13570-
fi
13571-
13572-
13573-
if test $ac_cv_header_stdbool_h = yes; then
13574-
13575-
$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13576-
13577-
fi
13578-
13579-
1358013486
for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h sys/epoll.h sys/event.h sys/personality.h sys/prctl.h sys/procctl.h sys/signalfd.h sys/ucred.h termios.h ucred.h
1358113487
do :
1358213488
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -15379,9 +15285,7 @@ $as_echo_n "checking size of bool... " >&6; }
1537915285
if ${ac_cv_sizeof_bool+:} false; then :
1538015286
$as_echo_n "(cached) " >&6
1538115287
else
15382-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#ifdef HAVE_STDBOOL_H
15383-
#include <stdbool.h>
15384-
#endif
15288+
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
1538515289
"; then :
1538615290

1538715291
else
@@ -15407,7 +15311,7 @@ _ACEOF
1540715311

1540815312

1540915313

15410-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
15314+
if test "$ac_cv_sizeof_bool" = 1; then
1541115315

1541215316
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
1541315317

configure.ac

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,8 +1492,6 @@ AC_SUBST(UUID_LIBS)
14921492
## Header files
14931493
##
14941494

1495-
AC_HEADER_STDBOOL
1496-
14971495
AC_CHECK_HEADERS(m4_normalize([
14981496
atomic.h
14991497
copyfile.h
@@ -1762,14 +1760,11 @@ if test "$ac_cv_sizeof_off_t" -lt 8; then
17621760
fi
17631761
fi
17641762

1765-
AC_CHECK_SIZEOF([bool], [],
1766-
[#ifdef HAVE_STDBOOL_H
1767-
#include <stdbool.h>
1768-
#endif])
1763+
AC_CHECK_SIZEOF([bool], [], [#include <stdbool.h>])
17691764

1770-
dnl We use <stdbool.h> if we have it and it declares type bool as having
1771-
dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1772-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
1765+
dnl We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1766+
dnl will fall back to declaring bool as unsigned char.
1767+
if test "$ac_cv_sizeof_bool" = 1; then
17731768
AC_DEFINE([PG_USE_STDBOOL], 1,
17741769
[Define to 1 to use <stdbool.h> to define type bool.])
17751770
fi

meson.build

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,12 +1773,9 @@ if cc.compiles('''
17731773
endif
17741774

17751775

1776-
# We use <stdbool.h> if we have it and it declares type bool as having
1777-
# size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1778-
if cc.has_type('_Bool', args: test_c_args) \
1779-
and cc.has_type('bool', prefix: '#include <stdbool.h>', args: test_c_args) \
1780-
and cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
1781-
cdata.set('HAVE__BOOL', 1)
1776+
# We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1777+
# will fall back to declaring bool as unsigned char.
1778+
if cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
17821779
cdata.set('PG_USE_STDBOOL', 1)
17831780
endif
17841781

src/include/c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ typedef void (*pg_funcptr_t) (void);
435435
* bool
436436
* Boolean value, either true or false.
437437
*
438-
* We use stdbool.h if available and its bool has size 1. That's useful for
438+
* We use stdbool.h if bool has size 1 after including it. That's useful for
439439
* better compiler and debugger output and for compatibility with third-party
440440
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
441441
* there are static assertions around the code to prevent that.

src/include/pg_config.h.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,6 @@
390390
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
391391
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
392392

393-
/* Define to 1 if stdbool.h conforms to C99. */
394-
#undef HAVE_STDBOOL_H
395-
396393
/* Define to 1 if you have the <stdint.h> header file. */
397394
#undef HAVE_STDINT_H
398395

@@ -522,9 +519,6 @@
522519
/* Define to 1 if you have XSAVE intrinsics. */
523520
#undef HAVE_XSAVE_INTRINSICS
524521

525-
/* Define to 1 if the system has the type `_Bool'. */
526-
#undef HAVE__BOOL
527-
528522
/* Define to 1 if your compiler understands __builtin_bswap16. */
529523
#undef HAVE__BUILTIN_BSWAP16
530524

0 commit comments

Comments
 (0)