Skip to content

Commit 0813a5e

Browse files
committed
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 5f46439 commit 0813a5e

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
@@ -2096,116 +2096,116 @@ $as_echo "$ac_res" >&6; }
20962096

20972097
} # ac_fn_c_check_func
20982098

2099-
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2100-
# -------------------------------------------
2101-
# Tests whether TYPE exists after having included INCLUDES, setting cache
2102-
# variable VAR accordingly.
2103-
ac_fn_c_check_type ()
2099+
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2100+
# ----------------------------------------------------
2101+
# Tries to find if the field MEMBER exists in type AGGR, after including
2102+
# INCLUDES, setting cache variable VAR accordingly.
2103+
ac_fn_c_check_member ()
21042104
{
21052105
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2106-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2107-
$as_echo_n "checking for $2... " >&6; }
2108-
if eval \${$3+:} false; then :
2106+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2107+
$as_echo_n "checking for $2.$3... " >&6; }
2108+
if eval \${$4+:} false; then :
21092109
$as_echo_n "(cached) " >&6
21102110
else
2111-
eval "$3=no"
21122111
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21132112
/* end confdefs.h. */
2114-
$4
2113+
$5
21152114
int
21162115
main ()
21172116
{
2118-
if (sizeof ($2))
2119-
return 0;
2117+
static $2 ac_aggr;
2118+
if (ac_aggr.$3)
2119+
return 0;
21202120
;
21212121
return 0;
21222122
}
21232123
_ACEOF
21242124
if ac_fn_c_try_compile "$LINENO"; then :
2125+
eval "$4=yes"
2126+
else
21252127
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21262128
/* end confdefs.h. */
2127-
$4
2129+
$5
21282130
int
21292131
main ()
21302132
{
2131-
if (sizeof (($2)))
2132-
return 0;
2133+
static $2 ac_aggr;
2134+
if (sizeof ac_aggr.$3)
2135+
return 0;
21332136
;
21342137
return 0;
21352138
}
21362139
_ACEOF
21372140
if ac_fn_c_try_compile "$LINENO"; then :
2138-
2141+
eval "$4=yes"
21392142
else
2140-
eval "$3=yes"
2143+
eval "$4=no"
21412144
fi
21422145
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21432146
fi
21442147
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21452148
fi
2146-
eval ac_res=\$$3
2149+
eval ac_res=\$$4
21472150
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21482151
$as_echo "$ac_res" >&6; }
21492152
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21502153

2151-
} # ac_fn_c_check_type
2154+
} # ac_fn_c_check_member
21522155

2153-
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2154-
# ----------------------------------------------------
2155-
# Tries to find if the field MEMBER exists in type AGGR, after including
2156-
# INCLUDES, setting cache variable VAR accordingly.
2157-
ac_fn_c_check_member ()
2156+
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2157+
# -------------------------------------------
2158+
# Tests whether TYPE exists after having included INCLUDES, setting cache
2159+
# variable VAR accordingly.
2160+
ac_fn_c_check_type ()
21582161
{
21592162
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2160-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2161-
$as_echo_n "checking for $2.$3... " >&6; }
2162-
if eval \${$4+:} false; then :
2163+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2164+
$as_echo_n "checking for $2... " >&6; }
2165+
if eval \${$3+:} false; then :
21632166
$as_echo_n "(cached) " >&6
21642167
else
2168+
eval "$3=no"
21652169
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21662170
/* end confdefs.h. */
2167-
$5
2171+
$4
21682172
int
21692173
main ()
21702174
{
2171-
static $2 ac_aggr;
2172-
if (ac_aggr.$3)
2173-
return 0;
2175+
if (sizeof ($2))
2176+
return 0;
21742177
;
21752178
return 0;
21762179
}
21772180
_ACEOF
21782181
if ac_fn_c_try_compile "$LINENO"; then :
2179-
eval "$4=yes"
2180-
else
21812182
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21822183
/* end confdefs.h. */
2183-
$5
2184+
$4
21842185
int
21852186
main ()
21862187
{
2187-
static $2 ac_aggr;
2188-
if (sizeof ac_aggr.$3)
2189-
return 0;
2188+
if (sizeof (($2)))
2189+
return 0;
21902190
;
21912191
return 0;
21922192
}
21932193
_ACEOF
21942194
if ac_fn_c_try_compile "$LINENO"; then :
2195-
eval "$4=yes"
2195+
21962196
else
2197-
eval "$4=no"
2197+
eval "$3=yes"
21982198
fi
21992199
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
22002200
fi
22012201
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
22022202
fi
2203-
eval ac_res=\$$4
2203+
eval ac_res=\$$3
22042204
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
22052205
$as_echo "$ac_res" >&6; }
22062206
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
22072207

2208-
} # ac_fn_c_check_member
2208+
} # ac_fn_c_check_type
22092209

22102210
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
22112211
# --------------------------------------------
@@ -13349,100 +13349,6 @@ fi
1334913349
## Header files
1335013350
##
1335113351

13352-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
13353-
$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
13354-
if ${ac_cv_header_stdbool_h+:} false; then :
13355-
$as_echo_n "(cached) " >&6
13356-
else
13357-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13358-
/* end confdefs.h. */
13359-
13360-
#include <stdbool.h>
13361-
#ifndef bool
13362-
"error: bool is not defined"
13363-
#endif
13364-
#ifndef false
13365-
"error: false is not defined"
13366-
#endif
13367-
#if false
13368-
"error: false is not 0"
13369-
#endif
13370-
#ifndef true
13371-
"error: true is not defined"
13372-
#endif
13373-
#if true != 1
13374-
"error: true is not 1"
13375-
#endif
13376-
#ifndef __bool_true_false_are_defined
13377-
"error: __bool_true_false_are_defined is not defined"
13378-
#endif
13379-
13380-
struct s { _Bool s: 1; _Bool t; } s;
13381-
13382-
char a[true == 1 ? 1 : -1];
13383-
char b[false == 0 ? 1 : -1];
13384-
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
13385-
char d[(bool) 0.5 == true ? 1 : -1];
13386-
/* See body of main program for 'e'. */
13387-
char f[(_Bool) 0.0 == false ? 1 : -1];
13388-
char g[true];
13389-
char h[sizeof (_Bool)];
13390-
char i[sizeof s.t];
13391-
enum { j = false, k = true, l = false * true, m = true * 256 };
13392-
/* The following fails for
13393-
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
13394-
_Bool n[m];
13395-
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
13396-
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
13397-
/* Catch a bug in an HP-UX C compiler. See
13398-
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
13399-
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
13400-
*/
13401-
_Bool q = true;
13402-
_Bool *pq = &q;
13403-
13404-
int
13405-
main ()
13406-
{
13407-
13408-
bool e = &s;
13409-
*pq |= q;
13410-
*pq |= ! q;
13411-
/* Refer to every declared value, to avoid compiler optimizations. */
13412-
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
13413-
+ !m + !n + !o + !p + !q + !pq);
13414-
13415-
;
13416-
return 0;
13417-
}
13418-
_ACEOF
13419-
if ac_fn_c_try_compile "$LINENO"; then :
13420-
ac_cv_header_stdbool_h=yes
13421-
else
13422-
ac_cv_header_stdbool_h=no
13423-
fi
13424-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13425-
fi
13426-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5
13427-
$as_echo "$ac_cv_header_stdbool_h" >&6; }
13428-
ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default"
13429-
if test "x$ac_cv_type__Bool" = xyes; then :
13430-
13431-
cat >>confdefs.h <<_ACEOF
13432-
#define HAVE__BOOL 1
13433-
_ACEOF
13434-
13435-
13436-
fi
13437-
13438-
13439-
if test $ac_cv_header_stdbool_h = yes; then
13440-
13441-
$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13442-
13443-
fi
13444-
13445-
1344613352
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
1344713353
do :
1344813354
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -15232,9 +15138,7 @@ $as_echo_n "checking size of bool... " >&6; }
1523215138
if ${ac_cv_sizeof_bool+:} false; then :
1523315139
$as_echo_n "(cached) " >&6
1523415140
else
15235-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#ifdef HAVE_STDBOOL_H
15236-
#include <stdbool.h>
15237-
#endif
15141+
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
1523815142
"; then :
1523915143

1524015144
else
@@ -15260,7 +15164,7 @@ _ACEOF
1526015164

1526115165

1526215166

15263-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
15167+
if test "$ac_cv_sizeof_bool" = 1; then
1526415168

1526515169
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
1526615170

configure.ac

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,6 @@ AC_SUBST(UUID_LIBS)
14631463
## Header files
14641464
##
14651465

1466-
AC_HEADER_STDBOOL
1467-
14681466
AC_CHECK_HEADERS(m4_normalize([
14691467
atomic.h
14701468
copyfile.h
@@ -1726,14 +1724,11 @@ if test "$ac_cv_sizeof_off_t" -lt 8; then
17261724
fi
17271725
fi
17281726

1729-
AC_CHECK_SIZEOF([bool], [],
1730-
[#ifdef HAVE_STDBOOL_H
1731-
#include <stdbool.h>
1732-
#endif])
1727+
AC_CHECK_SIZEOF([bool], [], [#include <stdbool.h>])
17331728

1734-
dnl We use <stdbool.h> if we have it and it declares type bool as having
1735-
dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1736-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
1729+
dnl We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1730+
dnl will fall back to declaring bool as unsigned char.
1731+
if test "$ac_cv_sizeof_bool" = 1; then
17371732
AC_DEFINE([PG_USE_STDBOOL], 1,
17381733
[Define to 1 to use <stdbool.h> to define type bool.])
17391734
fi

meson.build

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

17661766

1767-
# We use <stdbool.h> if we have it and it declares type bool as having
1768-
# size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1769-
if cc.has_type('_Bool', args: test_c_args) \
1770-
and cc.has_type('bool', prefix: '#include <stdbool.h>', args: test_c_args) \
1771-
and cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
1772-
cdata.set('HAVE__BOOL', 1)
1767+
# We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1768+
# will fall back to declaring bool as unsigned char.
1769+
if cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
17731770
cdata.set('PG_USE_STDBOOL', 1)
17741771
endif
17751772

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
@@ -387,9 +387,6 @@
387387
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
388388
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
389389

390-
/* Define to 1 if stdbool.h conforms to C99. */
391-
#undef HAVE_STDBOOL_H
392-
393390
/* Define to 1 if you have the <stdint.h> header file. */
394391
#undef HAVE_STDINT_H
395392

@@ -519,9 +516,6 @@
519516
/* Define to 1 if you have XSAVE intrinsics. */
520517
#undef HAVE_XSAVE_INTRINSICS
521518

522-
/* Define to 1 if the system has the type `_Bool'. */
523-
#undef HAVE__BOOL
524-
525519
/* Define to 1 if your compiler understands __builtin_bswap16. */
526520
#undef HAVE__BUILTIN_BSWAP16
527521

0 commit comments

Comments
 (0)