Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13242b6

Browse files
committed
Assume that <stdbool.h> conforms to the C standard.
Previously we checked "for <stdbool.h> that conforms to C99" usingautoconf's AC_HEADER_STDBOOL macro. We've required C99 since PostgreSQL12, so the test was redundant, and under C23 it was broken: autoconf2.69's implementation doesn't understand C23's new empty header (themacros it's looking for went away, replaced by language keywords).Later autoconf versions fixed that, but let's just remove theanachronistic test.HAVE_STDBOOL_H and HAVE__BOOL will no longer be defined, but theyweren't directly tested in core or likely extensions (except in 11, seebelow). PG_USE_STDBOOL (or USE_STDBOOL in 11 and 12) is still definedwhen 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 wouldfail to compile under C23 as revealed by the broken test. (We'llprobably clean that dead code up in master, but here we want a minimalback-patchable change.)This came to our attention when GCC 15 recently started using using C23by default and failed to compile the replacement code, as reported bySam James and build farm animal alligator.Back-patch to all supported releases, and then two older versions thatalso 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 onlyassumes C89 so it now uses AC_CHECK_HEADERS instead of the overly pickyAC_HEADER_STDBOOL. (I could find no discussion of which historicalsystems had <stdbool.h> but failed the conformance test; if they everexisted, they surely aren't relevant to that policy's goals.)[1]https://wiki.postgresql.org/wiki/Committing_checklist#PoliciesReported-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 parent8aefd8b commit13242b6

File tree

5 files changed

+48
-157
lines changed

5 files changed

+48
-157
lines changed

‎configure

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

20752075
} # ac_fn_c_check_func
20762076

2077-
#ac_fn_c_check_type LINENOTYPE VAR INCLUDES
2078-
# -------------------------------------------
2079-
#Tests whether TYPE exists after having included INCLUDES, setting cache
2080-
# variable VAR accordingly.
2081-
ac_fn_c_check_type ()
2077+
#ac_fn_c_check_member LINENOAGGR MEMBER VAR INCLUDES
2078+
# ----------------------------------------------------
2079+
#Tries to find if the field MEMBER exists in type AGGR, after including
2080+
#INCLUDES, setting cachevariable VAR accordingly.
2081+
ac_fn_c_check_member ()
20822082
{
20832083
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2084-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2085-
$as_echo_n "checking for $2... " >&6; }
2086-
if eval \${$3+:} false; then :
2084+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2085+
$as_echo_n "checking for $2.$3... " >&6; }
2086+
if eval \${$4+:} false; then :
20872087
$as_echo_n "(cached) " >&6
20882088
else
2089-
eval "$3=no"
20902089
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
20912090
/* end confdefs.h. */
2092-
$4
2091+
$5
20932092
int
20942093
main ()
20952094
{
2096-
if (sizeof ($2))
2097-
return 0;
2095+
static $2 ac_aggr;
2096+
if (ac_aggr.$3)
2097+
return 0;
20982098
;
20992099
return 0;
21002100
}
21012101
_ACEOF
21022102
if ac_fn_c_try_compile "$LINENO"; then :
2103+
eval "$4=yes"
2104+
else
21032105
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21042106
/* end confdefs.h. */
2105-
$4
2107+
$5
21062108
int
21072109
main ()
21082110
{
2109-
if (sizeof (($2)))
2110-
return 0;
2111+
static $2 ac_aggr;
2112+
if (sizeof ac_aggr.$3)
2113+
return 0;
21112114
;
21122115
return 0;
21132116
}
21142117
_ACEOF
21152118
if ac_fn_c_try_compile "$LINENO"; then :
2116-
2119+
eval "$4=yes"
21172120
else
2118-
eval "$3=yes"
2121+
eval "$4=no"
21192122
fi
21202123
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21212124
fi
21222125
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21232126
fi
2124-
eval ac_res=\$$3
2127+
eval ac_res=\$$4
21252128
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21262129
$as_echo "$ac_res" >&6; }
21272130
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21282131

2129-
} #ac_fn_c_check_type
2132+
} #ac_fn_c_check_member
21302133

2131-
#ac_fn_c_check_member LINENOAGGR MEMBER VAR INCLUDES
2132-
# ----------------------------------------------------
2133-
#Tries to find if the field MEMBERexistsin type AGGR, after including
2134-
#INCLUDES, setting cachevariable VAR accordingly.
2135-
ac_fn_c_check_member ()
2134+
#ac_fn_c_check_type LINENOTYPE VAR INCLUDES
2135+
# -------------------------------------------
2136+
#Tests whether TYPEexistsafter having included INCLUDES, setting cache
2137+
# variable VAR accordingly.
2138+
ac_fn_c_check_type ()
21362139
{
21372140
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2138-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
2139-
$as_echo_n "checking for $2.$3... " >&6; }
2140-
if eval \${$4+:} false; then :
2141+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
2142+
$as_echo_n "checking for $2... " >&6; }
2143+
if eval \${$3+:} false; then :
21412144
$as_echo_n "(cached) " >&6
21422145
else
2146+
eval "$3=no"
21432147
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21442148
/* end confdefs.h. */
2145-
$5
2149+
$4
21462150
int
21472151
main ()
21482152
{
2149-
static $2 ac_aggr;
2150-
if (ac_aggr.$3)
2151-
return 0;
2153+
if (sizeof ($2))
2154+
return 0;
21522155
;
21532156
return 0;
21542157
}
21552158
_ACEOF
21562159
if ac_fn_c_try_compile "$LINENO"; then :
2157-
eval "$4=yes"
2158-
else
21592160
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
21602161
/* end confdefs.h. */
2161-
$5
2162+
$4
21622163
int
21632164
main ()
21642165
{
2165-
static $2 ac_aggr;
2166-
if (sizeof ac_aggr.$3)
2167-
return 0;
2166+
if (sizeof (($2)))
2167+
return 0;
21682168
;
21692169
return 0;
21702170
}
21712171
_ACEOF
21722172
if ac_fn_c_try_compile "$LINENO"; then :
2173-
eval "$4=yes"
2173+
21742174
else
2175-
eval "$4=no"
2175+
eval "$3=yes"
21762176
fi
21772177
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21782178
fi
21792179
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
21802180
fi
2181-
eval ac_res=\$$4
2181+
eval ac_res=\$$3
21822182
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
21832183
$as_echo "$ac_res" >&6; }
21842184
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
21852185

2186-
} #ac_fn_c_check_member
2186+
} #ac_fn_c_check_type
21872187

21882188
# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
21892189
# --------------------------------------------
@@ -13528,100 +13528,6 @@ fi
1352813528
## Header files
1352913529
##
1353013530

13531-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
13532-
$as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
13533-
if ${ac_cv_header_stdbool_h+:} false; then :
13534-
$as_echo_n "(cached) " >&6
13535-
else
13536-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13537-
/* end confdefs.h. */
13538-
13539-
#include <stdbool.h>
13540-
#ifndef bool
13541-
"error: bool is not defined"
13542-
#endif
13543-
#ifndef false
13544-
"error: false is not defined"
13545-
#endif
13546-
#if false
13547-
"error: false is not 0"
13548-
#endif
13549-
#ifndef true
13550-
"error: true is not defined"
13551-
#endif
13552-
#if true != 1
13553-
"error: true is not 1"
13554-
#endif
13555-
#ifndef __bool_true_false_are_defined
13556-
"error: __bool_true_false_are_defined is not defined"
13557-
#endif
13558-
13559-
struct s { _Bool s: 1; _Bool t; } s;
13560-
13561-
char a[true == 1 ? 1 : -1];
13562-
char b[false == 0 ? 1 : -1];
13563-
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
13564-
char d[(bool) 0.5 == true ? 1 : -1];
13565-
/* See body of main program for 'e'. */
13566-
char f[(_Bool) 0.0 == false ? 1 : -1];
13567-
char g[true];
13568-
char h[sizeof (_Bool)];
13569-
char i[sizeof s.t];
13570-
enum { j = false, k = true, l = false * true, m = true * 256 };
13571-
/* The following fails for
13572-
HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
13573-
_Bool n[m];
13574-
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
13575-
char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
13576-
/* Catch a bug in an HP-UX C compiler. See
13577-
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
13578-
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
13579-
*/
13580-
_Bool q = true;
13581-
_Bool *pq = &q;
13582-
13583-
int
13584-
main ()
13585-
{
13586-
13587-
bool e = &s;
13588-
*pq |= q;
13589-
*pq |= ! q;
13590-
/* Refer to every declared value, to avoid compiler optimizations. */
13591-
return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
13592-
+ !m + !n + !o + !p + !q + !pq);
13593-
13594-
;
13595-
return 0;
13596-
}
13597-
_ACEOF
13598-
if ac_fn_c_try_compile "$LINENO"; then :
13599-
ac_cv_header_stdbool_h=yes
13600-
else
13601-
ac_cv_header_stdbool_h=no
13602-
fi
13603-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13604-
fi
13605-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdbool_h" >&5
13606-
$as_echo "$ac_cv_header_stdbool_h" >&6; }
13607-
ac_fn_c_check_type "$LINENO" "_Bool" "ac_cv_type__Bool" "$ac_includes_default"
13608-
if test "x$ac_cv_type__Bool" = xyes; then :
13609-
13610-
cat >>confdefs.h <<_ACEOF
13611-
#define HAVE__BOOL 1
13612-
_ACEOF
13613-
13614-
13615-
fi
13616-
13617-
13618-
if test $ac_cv_header_stdbool_h = yes; then
13619-
13620-
$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13621-
13622-
fi
13623-
13624-
1362513531
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/sockio.h sys/tas.h sys/un.h termios.h ucred.h wctype.h
1362613532
do :
1362713533
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -15476,9 +15382,7 @@ $as_echo_n "checking size of bool... " >&6; }
1547615382
if ${ac_cv_sizeof_bool+:} false; then :
1547715383
$as_echo_n "(cached) " >&6
1547815384
else
15479-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#ifdef HAVE_STDBOOL_H
15480-
#include <stdbool.h>
15481-
#endif
15385+
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
1548215386
"; then :
1548315387

1548415388
else
@@ -15504,7 +15408,7 @@ _ACEOF
1550415408

1550515409

1550615410

15507-
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
15411+
if test "$ac_cv_sizeof_bool" = 1; then
1550815412

1550915413
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
1551015414

‎configure.in

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,6 @@ AC_SUBST(UUID_LIBS)
13831383
## Header files
13841384
##
13851385

1386-
AC_HEADER_STDBOOL
1387-
13881386
AC_CHECK_HEADERS(m4_normalize([
13891387
atomic.h
13901388
copyfile.h
@@ -1693,14 +1691,11 @@ if test "$ac_cv_sizeof_off_t" -lt 8 -a "$segsize" != "1"; then
16931691
AC_MSG_ERROR([Large file support is not enabled. Segment size cannot be larger than 1GB.])
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> ifwe have it and it declares type bool as having
1702-
dnlsize 1. Otherwise, c.hwill 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> ifbool 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

‎src/include/c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ typedef void (*pg_funcptr_t) (void);
343343
* bool
344344
*Boolean value, either true or false.
345345
*
346-
* We use stdbool.h ifavailable and itsbool has size 1. That's useful for
346+
* We use stdbool.h if bool has size 1 after including it. That's useful for
347347
* better compiler and debugger output and for compatibility with third-party
348348
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
349349
* 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
@@ -491,9 +491,6 @@
491491
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
492492
#undef HAVE_SSL_CTX_SET_NUM_TICKETS
493493

494-
/* Define to 1 if stdbool.h conforms to C99. */
495-
#undef HAVE_STDBOOL_H
496-
497494
/* Define to 1 if you have the <stdint.h> header file. */
498495
#undef HAVE_STDINT_H
499496

@@ -692,9 +689,6 @@
692689
/* Define to 1 if the assembler supports X86_64's POPCNTQ instruction. */
693690
#undef HAVE_X86_64_POPCNTQ
694691

695-
/* Define to 1 if the system has the type `_Bool'. */
696-
#undef HAVE__BOOL
697-
698692
/* Define to 1 if your compiler understands __builtin_bswap16. */
699693
#undef HAVE__BUILTIN_BSWAP16
700694

‎src/tools/msvc/Solution.pm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ sub GenerateFiles
354354
HAVE_SPINLOCKS=> 1,
355355
HAVE_SSL_CTX_SET_NUM_TICKETS=>undef,
356356
HAVE_SRANDOM=>undef,
357-
HAVE_STDBOOL_H=> 1,
358357
HAVE_STDINT_H=> 1,
359358
HAVE_STDLIB_H=> 1,
360359
HAVE_STRCHRNUL=>undef,
@@ -421,7 +420,6 @@ sub GenerateFiles
421420
HAVE_X509_GET_SIGNATURE_NID=> 1,
422421
HAVE_X509_GET_SIGNATURE_INFO=>undef,
423422
HAVE_X86_64_POPCNTQ=>undef,
424-
HAVE__BOOL=>undef,
425423
HAVE__BUILTIN_BSWAP16=>undef,
426424
HAVE__BUILTIN_BSWAP32=>undef,
427425
HAVE__BUILTIN_BSWAP64=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp