Skip to content

Commit bc5a4df

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 <[email protected]> Reviewed-by: Peter Eisentraut <[email protected]> (master version) Reviewed-by: Tom Lane <[email protected]> (approach) Discussion: https://www.postgresql.org/message-id/flat/87o72eo9iu.fsf%40gentoo.org
1 parent d4d1194 commit bc5a4df

File tree

5 files changed

+51
-161
lines changed

5 files changed

+51
-161
lines changed

configure

+43-139
Original file line numberDiff line numberDiff line change
@@ -2094,116 +2094,116 @@ $as_echo "$ac_res" >&6; }
20942094

20952095
} # ac_fn_c_check_func
20962096

2097-
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2098-
# -------------------------------------------
2099-
# Tests whether TYPE exists after having included INCLUDES, setting cache
2100-
# variable VAR accordingly.
2101-
ac_fn_c_check_type ()
2097+
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2098+
# ----------------------------------------------------
2099+
# Tries to find if the field MEMBER exists in type AGGR, after including
2100+
# INCLUDES, setting cache variable VAR accordingly.
2101+
ac_fn_c_check_member ()
21022102
{
21032103
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2104-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2105-
$as_echo_n "checking for $2... " >&6; }
2106-
if eval \${$3+:} false; then :
2104+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2105+
$as_echo_n "checking for $2.$3... " >&6; }
2106+
if eval \${$4+:} false; then :
21072107
$as_echo_n "(cached) " >&6
21082108
else
2109-
eval "$3=no"
21102109
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21112110
/* end confdefs.h. */
2112-
$4
2111+
$5
21132112
int
21142113
main ()
21152114
{
2116-
if (sizeof ($2))
2117-
return 0;
2115+
static $2 ac_aggr;
2116+
if (ac_aggr.$3)
2117+
return 0;
21182118
;
21192119
return 0;
21202120
}
21212121
_ACEOF
21222122
if ac_fn_c_try_compile "$LINENO"; then :
2123+
eval "$4=yes"
2124+
else
21232125
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21242126
/* end confdefs.h. */
2125-
$4
2127+
$5
21262128
int
21272129
main ()
21282130
{
2129-
if (sizeof (($2)))
2130-
return 0;
2131+
static $2 ac_aggr;
2132+
if (sizeof ac_aggr.$3)
2133+
return 0;
21312134
;
21322135
return 0;
21332136
}
21342137
_ACEOF
21352138
if ac_fn_c_try_compile "$LINENO"; then :
2136-
2139+
eval "$4=yes"
21372140
else
2138-
eval "$3=yes"
2141+
eval "$4=no"
21392142
fi
21402143
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21412144
fi
21422145
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21432146
fi
2144-
eval ac_res=\$$3
2147+
eval ac_res=\$$4
21452148
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21462149
$as_echo "$ac_res" >&6; }
21472150
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21482151

2149-
} # ac_fn_c_check_type
2152+
} # ac_fn_c_check_member
21502153

2151-
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2152-
# ----------------------------------------------------
2153-
# Tries to find if the field MEMBER exists in type AGGR, after including
2154-
# INCLUDES, setting cache variable VAR accordingly.
2155-
ac_fn_c_check_member ()
2154+
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2155+
# -------------------------------------------
2156+
# Tests whether TYPE exists after having included INCLUDES, setting cache
2157+
# variable VAR accordingly.
2158+
ac_fn_c_check_type ()
21562159
{
21572160
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2158-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2159-
$as_echo_n "checking for $2.$3... " >&6; }
2160-
if eval \${$4+:} false; then :
2161+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2162+
$as_echo_n "checking for $2... " >&6; }
2163+
if eval \${$3+:} false; then :
21612164
$as_echo_n "(cached) " >&6
21622165
else
2166+
eval "$3=no"
21632167
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21642168
/* end confdefs.h. */
2165-
$5
2169+
$4
21662170
int
21672171
main ()
21682172
{
2169-
static $2 ac_aggr;
2170-
if (ac_aggr.$3)
2171-
return 0;
2173+
if (sizeof ($2))
2174+
return 0;
21722175
;
21732176
return 0;
21742177
}
21752178
_ACEOF
21762179
if ac_fn_c_try_compile "$LINENO"; then :
2177-
eval "$4=yes"
2178-
else
21792180
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21802181
/* end confdefs.h. */
2181-
$5
2182+
$4
21822183
int
21832184
main ()
21842185
{
2185-
static $2 ac_aggr;
2186-
if (sizeof ac_aggr.$3)
2187-
return 0;
2186+
if (sizeof (($2)))
2187+
return 0;
21882188
;
21892189
return 0;
21902190
}
21912191
_ACEOF
21922192
if ac_fn_c_try_compile "$LINENO"; then :
2193-
eval "$4=yes"
2193+
21942194
else
2195-
eval "$4=no"
2195+
eval "$3=yes"
21962196
fi
21972197
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21982198
fi
21992199
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
22002200
fi
2201-
eval ac_res=\$$4
2201+
eval ac_res=\$$3
22022202
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
22032203
$as_echo "$ac_res" >&6; }
22042204
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
22052205

2206-
} # ac_fn_c_check_member
2206+
} # ac_fn_c_check_type
22072207

22082208
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
22092209
# --------------------------------------------
@@ -13227,100 +13227,6 @@ fi
1322713227
## Header files
1322813228
##
1322913229

13230-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
13231-
$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
13232-
if ${ac_cv_header_stdbool_h+:} false; then :
13233-
$as_echo_n "(cached) " >&6
13234-
else
13235-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13236-
/* end confdefs.h. */
13237-
13238-
#include <stdbool.h>
13239-
#ifndef bool
13240-
"error: bool is not defined"
13241-
#endif
13242-
#ifndef false
13243-
"error: false is not defined"
13244-
#endif
13245-
#if false
13246-
"error: false is not 0"
13247-
#endif
13248-
#ifndef true
13249-
"error: true is not defined"
13250-
#endif
13251-
#if true != 1
13252-
"error: true is not 1"
13253-
#endif
13254-
#ifndef __bool_true_false_are_defined
13255-
"error: __bool_true_false_are_defined is not defined"
13256-
#endif
13257-
13258-
struct s { _Bool s: 1; _Bool t; } s;
13259-
13260-
char a[true == 1 ? 1 : -1];
13261-
char b[false == 0 ? 1 : -1];
13262-
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
13263-
char d[(bool) 0.5 == true ? 1 : -1];
13264-
/* See body of main program for 'e'. */
13265-
char f[(_Bool) 0.0 == false ? 1 : -1];
13266-
char g[true];
13267-
char h[sizeof (_Bool)];
13268-
char i[sizeof s.t];
13269-
enum { j = false, k = true, l = false * true, m = true * 256 };
13270-
/* The following fails for
13271-
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
13272-
_Bool n[m];
13273-
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
13274-
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
13275-
/* Catch a bug in an HP-UX C compiler. See
13276-
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
13277-
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
13278-
*/
13279-
_Bool q = true;
13280-
_Bool *pq = &q;
13281-
13282-
int
13283-
main ()
13284-
{
13285-
13286-
bool e = &s;
13287-
*pq |= q;
13288-
*pq |= ! q;
13289-
/* Refer to every declared value, to avoid compiler optimizations. */
13290-
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
13291-
+ !m + !n + !o + !p + !q + !pq);
13292-
13293-
;
13294-
return 0;
13295-
}
13296-
_ACEOF
13297-
if ac_fn_c_try_compile "$LINENO"; then :
13298-
ac_cv_header_stdbool_h=yes
13299-
else
13300-
ac_cv_header_stdbool_h=no
13301-
fi
13302-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13303-
fi
13304-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5
13305-
$as_echo "$ac_cv_header_stdbool_h" >&6; }
13306-
ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default"
13307-
if test "x$ac_cv_type__Bool" = xyes; then :
13308-
13309-
cat >>confdefs.h <<_ACEOF
13310-
#define HAVE__BOOL 1
13311-
_ACEOF
13312-
13313-
13314-
fi
13315-
13316-
13317-
if test $ac_cv_header_stdbool_h = yes; then
13318-
13319-
$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13320-
13321-
fi
13322-
13323-
1332413230
for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.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 xlocale.h
1332513231
do :
1332613232
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -15061,9 +14967,7 @@ $as_echo_n "checking size of bool... " >&6; }
1506114967
if ${ac_cv_sizeof_bool+:} false; then :
1506214968
$as_echo_n "(cached) " >&6
1506314969
else
15064-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#ifdef HAVE_STDBOOL_H
15065-
#include <stdbool.h>
15066-
#endif
14970+
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
1506714971
"; then :
1506814972

1506914973
else
@@ -15089,7 +14993,7 @@ _ACEOF
1508914993

1509014994

1509114995

15092-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
14996+
if test "$ac_cv_sizeof_bool" = 1; then
1509314997

1509414998
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
1509514999

configure.ac

+4-9
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,6 @@ AC_SUBST(UUID_LIBS)
14321432
## Header files
14331433
##
14341434

1435-
AC_HEADER_STDBOOL
1436-
14371435
AC_CHECK_HEADERS(m4_normalize([
14381436
atomic.h
14391437
copyfile.h
@@ -1693,14 +1691,11 @@ if test "$ac_cv_sizeof_off_t" -lt 8; then
16931691
fi
16941692
fi
16951693

1696-
AC_CHECK_SIZEOF([bool], [],
1697-
[#ifdef HAVE_STDBOOL_H
1698-
#include <stdbool.h>
1699-
#endif])
1694+
AC_CHECK_SIZEOF([bool], [], [#include <stdbool.h>])
17001695

1701-
dnl We use <stdbool.h> if we have it and it declares type bool as having
1702-
dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1703-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
1696+
dnl We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1697+
dnl will fall back to declaring bool as unsigned char.
1698+
if test "$ac_cv_sizeof_bool" = 1; then
17041699
AC_DEFINE([PG_USE_STDBOOL], 1,
17051700
[Define to 1 to use <stdbool.h> to define type bool.])
17061701
fi

meson.build

+3-6
Original file line numberDiff line numberDiff line change
@@ -1755,12 +1755,9 @@ if cc.compiles('''
17551755
endif
17561756

17571757

1758-
# We use <stdbool.h> if we have it and it declares type bool as having
1759-
# size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1760-
if cc.has_type('_Bool', args: test_c_args) \
1761-
and cc.has_type('bool', prefix: '#include <stdbool.h>', args: test_c_args) \
1762-
and cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
1763-
cdata.set('HAVE__BOOL', 1)
1758+
# We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1759+
# will fall back to declaring bool as unsigned char.
1760+
if cc.sizeof('bool', prefix: '#include <stdbool.h>', args: test_c_args) == 1
17641761
cdata.set('PG_USE_STDBOOL', 1)
17651762
endif
17661763

src/include/c.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ typedef void (*pg_funcptr_t) (void);
450450
* bool
451451
* Boolean value, either true or false.
452452
*
453-
* We use stdbool.h if available and its bool has size 1. That's useful for
453+
* We use stdbool.h if bool has size 1 after including it. That's useful for
454454
* better compiler and debugger output and for compatibility with third-party
455455
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
456456
* there are static assertions around the code to prevent that.

src/include/pg_config.h.in

-6
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@
367367
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
368368
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
369369

370-
/* Define to 1 if stdbool.h conforms to C99. */
371-
#undef HAVE_STDBOOL_H
372-
373370
/* Define to 1 if you have the <stdint.h> header file. */
374371
#undef HAVE_STDINT_H
375372

@@ -499,9 +496,6 @@
499496
/* Define to 1 if you have XSAVE intrinsics. */
500497
#undef HAVE_XSAVE_INTRINSICS
501498

502-
/* Define to 1 if the system has the type `_Bool'. */
503-
#undef HAVE__BOOL
504-
505499
/* Define to 1 if your compiler understands __builtin_bswap16. */
506500
#undef HAVE__BUILTIN_BSWAP16
507501

0 commit comments

Comments
 (0)