Skip to content

Commit e087408

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 7ca388f commit e087408

File tree

5 files changed

+48
-157
lines changed

5 files changed

+48
-157
lines changed

configure

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

20862086
} # ac_fn_c_check_func
20872087

2088-
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2089-
# -------------------------------------------
2090-
# Tests whether TYPE exists after having included INCLUDES, setting cache
2091-
# variable VAR accordingly.
2092-
ac_fn_c_check_type ()
2088+
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2089+
# ----------------------------------------------------
2090+
# Tries to find if the field MEMBER exists in type AGGR, after including
2091+
# INCLUDES, setting cache variable VAR accordingly.
2092+
ac_fn_c_check_member ()
20932093
{
20942094
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2095-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2096-
$as_echo_n "checking for $2... " >&6; }
2097-
if eval \${$3+:} false; then :
2095+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2096+
$as_echo_n "checking for $2.$3... " >&6; }
2097+
if eval \${$4+:} false; then :
20982098
$as_echo_n "(cached) " >&6
20992099
else
2100-
eval "$3=no"
21012100
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21022101
/* end confdefs.h. */
2103-
$4
2102+
$5
21042103
int
21052104
main ()
21062105
{
2107-
if (sizeof ($2))
2108-
return 0;
2106+
static $2 ac_aggr;
2107+
if (ac_aggr.$3)
2108+
return 0;
21092109
;
21102110
return 0;
21112111
}
21122112
_ACEOF
21132113
if ac_fn_c_try_compile "$LINENO"; then :
2114+
eval "$4=yes"
2115+
else
21142116
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21152117
/* end confdefs.h. */
2116-
$4
2118+
$5
21172119
int
21182120
main ()
21192121
{
2120-
if (sizeof (($2)))
2121-
return 0;
2122+
static $2 ac_aggr;
2123+
if (sizeof ac_aggr.$3)
2124+
return 0;
21222125
;
21232126
return 0;
21242127
}
21252128
_ACEOF
21262129
if ac_fn_c_try_compile "$LINENO"; then :
2127-
2130+
eval "$4=yes"
21282131
else
2129-
eval "$3=yes"
2132+
eval "$4=no"
21302133
fi
21312134
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21322135
fi
21332136
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21342137
fi
2135-
eval ac_res=\$$3
2138+
eval ac_res=\$$4
21362139
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21372140
$as_echo "$ac_res" >&6; }
21382141
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21392142

2140-
} # ac_fn_c_check_type
2143+
} # ac_fn_c_check_member
21412144

2142-
# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
2143-
# ----------------------------------------------------
2144-
# Tries to find if the field MEMBER exists in type AGGR, after including
2145-
# INCLUDES, setting cache variable VAR accordingly.
2146-
ac_fn_c_check_member ()
2145+
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
2146+
# -------------------------------------------
2147+
# Tests whether TYPE exists after having included INCLUDES, setting cache
2148+
# variable VAR accordingly.
2149+
ac_fn_c_check_type ()
21472150
{
21482151
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2149-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2150-
$as_echo_n "checking for $2.$3... " >&6; }
2151-
if eval \${$4+:} false; then :
2152+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2153+
$as_echo_n "checking for $2... " >&6; }
2154+
if eval \${$3+:} false; then :
21522155
$as_echo_n "(cached) " >&6
21532156
else
2157+
eval "$3=no"
21542158
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21552159
/* end confdefs.h. */
2156-
$5
2160+
$4
21572161
int
21582162
main ()
21592163
{
2160-
static $2 ac_aggr;
2161-
if (ac_aggr.$3)
2162-
return 0;
2164+
if (sizeof ($2))
2165+
return 0;
21632166
;
21642167
return 0;
21652168
}
21662169
_ACEOF
21672170
if ac_fn_c_try_compile "$LINENO"; then :
2168-
eval "$4=yes"
2169-
else
21702171
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21712172
/* end confdefs.h. */
2172-
$5
2173+
$4
21732174
int
21742175
main ()
21752176
{
2176-
static $2 ac_aggr;
2177-
if (sizeof ac_aggr.$3)
2178-
return 0;
2177+
if (sizeof (($2)))
2178+
return 0;
21792179
;
21802180
return 0;
21812181
}
21822182
_ACEOF
21832183
if ac_fn_c_try_compile "$LINENO"; then :
2184-
eval "$4=yes"
2184+
21852185
else
2186-
eval "$4=no"
2186+
eval "$3=yes"
21872187
fi
21882188
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21892189
fi
21902190
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21912191
fi
2192-
eval ac_res=\$$4
2192+
eval ac_res=\$$3
21932193
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21942194
$as_echo "$ac_res" >&6; }
21952195
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21962196

2197-
} # ac_fn_c_check_member
2197+
} # ac_fn_c_check_type
21982198

21992199
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
22002200
# --------------------------------------------
@@ -13851,100 +13851,6 @@ fi
1385113851
## Header files
1385213852
##
1385313853

13854-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
13855-
$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
13856-
if ${ac_cv_header_stdbool_h+:} false; then :
13857-
$as_echo_n "(cached) " >&6
13858-
else
13859-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13860-
/* end confdefs.h. */
13861-
13862-
#include <stdbool.h>
13863-
#ifndef bool
13864-
"error: bool is not defined"
13865-
#endif
13866-
#ifndef false
13867-
"error: false is not defined"
13868-
#endif
13869-
#if false
13870-
"error: false is not 0"
13871-
#endif
13872-
#ifndef true
13873-
"error: true is not defined"
13874-
#endif
13875-
#if true != 1
13876-
"error: true is not 1"
13877-
#endif
13878-
#ifndef __bool_true_false_are_defined
13879-
"error: __bool_true_false_are_defined is not defined"
13880-
#endif
13881-
13882-
struct s { _Bool s: 1; _Bool t; } s;
13883-
13884-
char a[true == 1 ? 1 : -1];
13885-
char b[false == 0 ? 1 : -1];
13886-
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
13887-
char d[(bool) 0.5 == true ? 1 : -1];
13888-
/* See body of main program for 'e'. */
13889-
char f[(_Bool) 0.0 == false ? 1 : -1];
13890-
char g[true];
13891-
char h[sizeof (_Bool)];
13892-
char i[sizeof s.t];
13893-
enum { j = false, k = true, l = false * true, m = true * 256 };
13894-
/* The following fails for
13895-
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
13896-
_Bool n[m];
13897-
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
13898-
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
13899-
/* Catch a bug in an HP-UX C compiler. See
13900-
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
13901-
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
13902-
*/
13903-
_Bool q = true;
13904-
_Bool *pq = &q;
13905-
13906-
int
13907-
main ()
13908-
{
13909-
13910-
bool e = &s;
13911-
*pq |= q;
13912-
*pq |= ! q;
13913-
/* Refer to every declared value, to avoid compiler optimizations. */
13914-
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
13915-
+ !m + !n + !o + !p + !q + !pq);
13916-
13917-
;
13918-
return 0;
13919-
}
13920-
_ACEOF
13921-
if ac_fn_c_try_compile "$LINENO"; then :
13922-
ac_cv_header_stdbool_h=yes
13923-
else
13924-
ac_cv_header_stdbool_h=no
13925-
fi
13926-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13927-
fi
13928-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5
13929-
$as_echo "$ac_cv_header_stdbool_h" >&6; }
13930-
ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default"
13931-
if test "x$ac_cv_type__Bool" = xyes; then :
13932-
13933-
cat >>confdefs.h <<_ACEOF
13934-
#define HAVE__BOOL 1
13935-
_ACEOF
13936-
13937-
13938-
fi
13939-
13940-
13941-
if test $ac_cv_header_stdbool_h = yes; then
13942-
13943-
$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13944-
13945-
fi
13946-
13947-
1394813854
for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/signalfd.h sys/sockio.h sys/tas.h sys/uio.h sys/un.h termios.h ucred.h wctype.h
1394913855
do :
1395013856
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -15816,9 +15722,7 @@ $as_echo_n "checking size of bool... " >&6; }
1581615722
if ${ac_cv_sizeof_bool+:} false; then :
1581715723
$as_echo_n "(cached) " >&6
1581815724
else
15819-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#ifdef HAVE_STDBOOL_H
15820-
#include <stdbool.h>
15821-
#endif
15725+
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
1582215726
"; then :
1582315727

1582415728
else
@@ -15844,7 +15748,7 @@ _ACEOF
1584415748

1584515749

1584615750

15847-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
15751+
if test "$ac_cv_sizeof_bool" = 1; then
1584815752

1584915753
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
1585015754

configure.ac

+4-9
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,6 @@ AC_SUBST(UUID_LIBS)
14251425
## Header files
14261426
##
14271427

1428-
AC_HEADER_STDBOOL
1429-
14301428
AC_CHECK_HEADERS(m4_normalize([
14311429
atomic.h
14321430
copyfile.h
@@ -1741,14 +1739,11 @@ if test "$ac_cv_sizeof_off_t" -lt 8 -a "$segsize" != "1"; then
17411739
AC_MSG_ERROR([Large file support is not enabled. Segment size cannot be larger than 1GB.])
17421740
fi
17431741

1744-
AC_CHECK_SIZEOF([bool], [],
1745-
[#ifdef HAVE_STDBOOL_H
1746-
#include <stdbool.h>
1747-
#endif])
1742+
AC_CHECK_SIZEOF([bool], [], [#include <stdbool.h>])
17481743

1749-
dnl We use <stdbool.h> if we have it and it declares type bool as having
1750-
dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1751-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
1744+
dnl We use <stdbool.h> if bool has size 1 after including it. Otherwise, c.h
1745+
dnl will fall back to declaring bool as unsigned char.
1746+
if test "$ac_cv_sizeof_bool" = 1; then
17521747
AC_DEFINE([PG_USE_STDBOOL], 1,
17531748
[Define to 1 to use <stdbool.h> to define type bool.])
17541749
fi

src/include/c.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ typedef void (*pg_funcptr_t) (void);
398398
* bool
399399
* Boolean value, either true or false.
400400
*
401-
* We use stdbool.h if available and its bool has size 1. That's useful for
401+
* We use stdbool.h if bool has size 1 after including it. That's useful for
402402
* better compiler and debugger output and for compatibility with third-party
403403
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
404404
* 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
@@ -517,9 +517,6 @@
517517
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
518518
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
519519

520-
/* Define to 1 if stdbool.h conforms to C99. */
521-
#undef HAVE_STDBOOL_H
522-
523520
/* Define to 1 if you have the <stdint.h> header file. */
524521
#undef HAVE_STDINT_H
525522

@@ -730,9 +727,6 @@
730727
/* Define to 1 if the assembler supports X86_64's POPCNTQ instruction. */
731728
#undef HAVE_X86_64_POPCNTQ
732729

733-
/* Define to 1 if the system has the type `_Bool'. */
734-
#undef HAVE__BOOL
735-
736730
/* Define to 1 if your compiler understands __builtin_bswap16. */
737731
#undef HAVE__BUILTIN_BSWAP16
738732

src/tools/msvc/Solution.pm

-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ sub GenerateFiles
365365
HAVE_SPINLOCKS => 1,
366366
HAVE_SSL_CTX_SET_NUM_TICKETS => undef,
367367
HAVE_SRANDOM => undef,
368-
HAVE_STDBOOL_H => 1,
369368
HAVE_STDINT_H => 1,
370369
HAVE_STDLIB_H => 1,
371370
HAVE_STRCHRNUL => undef,
@@ -436,7 +435,6 @@ sub GenerateFiles
436435
HAVE_X509_GET_SIGNATURE_NID => 1,
437436
HAVE_X509_GET_SIGNATURE_INFO => undef,
438437
HAVE_X86_64_POPCNTQ => undef,
439-
HAVE__BOOL => undef,
440438
HAVE__BUILTIN_BSWAP16 => undef,
441439
HAVE__BUILTIN_BSWAP32 => undef,
442440
HAVE__BUILTIN_BSWAP64 => undef,

0 commit comments

Comments
 (0)