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

Commit97525bc

Browse files
committed
Require sizeof(bool) == 1.
The C standard says that sizeof(bool) is implementation-defined, but weknow of no current systems where it is not 1. The last known systemsseem to have been Apple macOS/PowerPC 10.5 and Microsoft Visual C++ 4,both long defunct.PostgreSQL has always required sizeof(bool) == 1 for the definition ofbool that it used, but previously it would define its own type if thesystem-provided bool had a different size. That was liable to causememory layout problems when interacting with system and third-partylibraries on (by now hypothetical) computers with wider _Bool, and nowC23 has introduced a new problem by making bool a built-in datatype(like C++), so the fallback code doesn't even compile. We couldprobably work around that, but then we'd be writing new untested codefor a computer that doesn't exist.Instead, delete the unreachable and C23-uncompilable fallback code, andlet existing static assertions fail if the system-provided bool is toowide. If we ever get a problem report from a real system, then it willbe time to figure out what to do about it in a way that also works onmodern compilers.Note on C++: Previously we avoided including <stdbool.h> or trying todefine a new bool type in headers that might be included by C++ code.These days we might as well just include <stdbool.h> unconditionally:it should be visible to C++11 but do nothing, just as in C23. Wealready include <stdint.h> without C++ guards in c.h, and that fallsunder the same C99-compatibility section of the C++11 standard as<stdbool.h>, so let's remove the guards here too.Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/3198438.1731895163%40sss.pgh.pa.us
1 parent4b03a27 commit97525bc

File tree

11 files changed

+8
-160
lines changed

11 files changed

+8
-160
lines changed

‎configure

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14958,47 +14958,6 @@ if test "$ac_cv_sizeof_off_t" -lt 8; then
1495814958
fi
1495914959
fi
1496014960

14961-
# The cast to long int works around a bug in the HP C Compiler
14962-
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
14963-
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
14964-
# This bug is HP SR number 8606223364.
14965-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of bool" >&5
14966-
$as_echo_n "checking size of bool... " >&6; }
14967-
if ${ac_cv_sizeof_bool+:} false; then :
14968-
$as_echo_n "(cached) " >&6
14969-
else
14970-
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (bool))" "ac_cv_sizeof_bool" "#include <stdbool.h>
14971-
"; then :
14972-
14973-
else
14974-
if test "$ac_cv_type_bool" = yes; then
14975-
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
14976-
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
14977-
as_fn_error 77 "cannot compute sizeof (bool)
14978-
See \`config.log' for more details" "$LINENO" 5; }
14979-
else
14980-
ac_cv_sizeof_bool=0
14981-
fi
14982-
fi
14983-
14984-
fi
14985-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_bool" >&5
14986-
$as_echo "$ac_cv_sizeof_bool" >&6; }
14987-
14988-
14989-
14990-
cat >>confdefs.h <<_ACEOF
14991-
#define SIZEOF_BOOL $ac_cv_sizeof_bool
14992-
_ACEOF
14993-
14994-
14995-
14996-
if test "$ac_cv_sizeof_bool" = 1; then
14997-
14998-
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
14999-
15000-
fi
15001-
1500214961

1500314962
##
1500414963
## Functions, global variables

‎configure.ac

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,15 +1691,6 @@ if test "$ac_cv_sizeof_off_t" -lt 8; then
16911691
fi
16921692
fi
16931693

1694-
AC_CHECK_SIZEOF([bool],[],[#include <stdbool.h>])
1695-
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
1699-
AC_DEFINE([PG_USE_STDBOOL],1,
1700-
[Define to 1 to use <stdbool.h> to define type bool.])
1701-
fi
1702-
17031694

17041695
##
17051696
## Functions, global variables

‎meson.build

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,13 +1755,6 @@ if cc.compiles('''
17551755
endif
17561756

17571757

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
1761-
cdata.set('PG_USE_STDBOOL',1)
1762-
endif
1763-
1764-
17651758
# Need to check a call with %m because netbsd supports gnu_printf but emits a
17661759
# warning for each use of %m.
17671760
printf_attributes= ['gnu_printf','__syslog__','printf']

‎src/backend/jit/llvm/llvmjit_types.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,9 @@ ExecEvalBoolSubroutineTemplate(ExprState *state,
117117
}
118118

119119
/*
120-
* Clang represents stdbool.h style booleans that are returned by functions
121-
* differently (as i1) than stored ones (as i8). Therefore we do not just need
122-
* TypeBool (above), but also a way to determine the width of a returned
123-
* integer. This allows us to keep compatible with non-stdbool using
124-
* architectures.
120+
* Clang represents bool returned by functions differently (as i1) than stored
121+
* ones (as i8). Therefore we do not just need TypeStorageBool (above), but
122+
* also a way to determine the width of a returned integer.
125123
*/
126124
externboolFunctionReturningBool(void);
127125
bool

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818

1919
#ifndefWIN32
2020
#include<dlfcn.h>
21-
22-
/*
23-
* On macOS, <dlfcn.h> insists on including <stdbool.h>. If we're not
24-
* using stdbool, undef bool to undo the damage.
25-
*/
26-
#ifndefPG_USE_STDBOOL
27-
#ifdefbool
28-
#undef bool
29-
#endif
30-
#endif
3121
#endif/* !WIN32 */
3222

3323
#include"fmgr.h"

‎src/include/c.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -450,37 +450,11 @@ typedef void (*pg_funcptr_t) (void);
450450
* bool
451451
*Boolean value, either true or false.
452452
*
453-
* We use stdbool.h if bool has size 1 after including it. That's useful for
454-
* better compiler and debugger output and for compatibility with third-party
455-
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
456-
* there are static assertions around the code to prevent that.
457-
*
458-
* For C++ compilers, we assume the compiler has a compatible built-in
459-
* definition of bool.
460-
*
461-
* See also the version of this code in src/interfaces/ecpg/include/ecpglib.h.
453+
* PostgreSQL currently cannot deal with bool of size other than 1; there are
454+
* static assertions around the code to prevent that.
462455
*/
463456

464-
#ifndef__cplusplus
465-
466-
#ifdefPG_USE_STDBOOL
467457
#include<stdbool.h>
468-
#else
469-
470-
#ifndefbool
471-
typedefunsignedcharbool;
472-
#endif
473-
474-
#ifndeftrue
475-
#definetrue((bool) 1)
476-
#endif
477-
478-
#ifndeffalse
479-
#definefalse((bool) 0)
480-
#endif
481-
482-
#endif/* not PG_USE_STDBOOL */
483-
#endif/* not C++ */
484458

485459

486460
/* ----------------------------------------------------------------

‎src/include/pg_config.h.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,6 @@
597597
/* Define to best printf format archetype, usually gnu_printf if available. */
598598
#undef PG_PRINTF_ATTRIBUTE
599599

600-
/* Define to 1 to use <stdbool.h> to define type bool. */
601-
#undef PG_USE_STDBOOL
602-
603600
/* PostgreSQL version as a string */
604601
#undef PG_VERSION
605602

@@ -630,9 +627,6 @@
630627
RELSEG_SIZE requires an initdb. */
631628
#undef RELSEG_SIZE
632629

633-
/* The size of `bool', as computed by sizeof. */
634-
#undef SIZEOF_BOOL
635-
636630
/* The size of `long', as computed by sizeof. */
637631
#undef SIZEOF_LONG
638632

‎src/interfaces/ecpg/include/ecpg_config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@
66

77
/* Define to 1 if `long long int' works and is 64 bits. */
88
#undef HAVE_LONG_LONG_INT_64
9-
10-
/* Define to 1 to use <stdbool.h> to define type bool. */
11-
#undef PG_USE_STDBOOL

‎src/interfaces/ecpg/include/ecpglib.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,14 @@
77
#ifndef_ECPGLIB_H
88
#define_ECPGLIB_H
99

10+
#include<stdbool.h>
1011
#include<string.h>
1112

1213
#include"ecpg_config.h"
1314
#include"ecpgtype.h"
1415
#include"libpq-fe.h"
1516
#include"sqlca.h"
1617

17-
/*
18-
* This is a small extract from c.h since we don't want to leak all postgres
19-
* definitions into ecpg programs; but we need to know what bool is.
20-
*/
21-
#ifndef__cplusplus
22-
23-
#ifdefPG_USE_STDBOOL
24-
#include<stdbool.h>
25-
#else
26-
27-
/*
28-
* We assume bool has been defined if true and false are. This avoids
29-
* duplicate-typedef errors if this file is included after c.h.
30-
*/
31-
#if !(defined(true)&& defined(false))
32-
typedefunsignedcharbool;
33-
#endif
34-
35-
#ifndeftrue
36-
#definetrue((bool) 1)
37-
#endif
38-
39-
#ifndeffalse
40-
#definefalse((bool) 0)
41-
#endif
42-
43-
#endif/* not PG_USE_STDBOOL */
44-
#endif/* not C++ */
45-
4618

4719
#ifdef__cplusplus
4820
extern"C"

‎src/interfaces/ecpg/include/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ecpg_inc = include_directories('.')
55
ecpg_conf_keys= [
66
'HAVE_LONG_INT_64',
77
'HAVE_LONG_LONG_INT_64',
8-
'PG_USE_STDBOOL',
98
]
109

1110
ecpg_conf_data=configuration_data()

‎src/pl/plperl/plperl_system.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,10 @@
7272
#endif
7373

7474
/*
75-
* Regarding bool, both PostgreSQL and Perl might use stdbool.h or not,
76-
* depending on configuration. If both agree, things are relatively harmless.
77-
* If not, things get tricky. If PostgreSQL does but Perl does not, define
78-
* HAS_BOOL here so that Perl does not redefine bool; this avoids compiler
79-
* warnings. If PostgreSQL does not but Perl does, we need to undefine bool
80-
* after we include the Perl headers; see below.
75+
* Define HAS_BOOL here so that Perl does not redefine bool. We included
76+
* <stdbool.h> in c.h.
8177
*/
82-
#ifdefPG_USE_STDBOOL
8378
#defineHAS_BOOL 1
84-
#endif
8579

8680
/*
8781
* Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code
@@ -180,19 +174,6 @@
180174
/* perl version and platform portability */
181175
#include"ppport.h"
182176

183-
/*
184-
* perl might have included stdbool.h. If we also did that earlier (see c.h),
185-
* then that's fine. If not, we probably rejected it for some reason. In
186-
* that case, undef bool and proceed with our own bool. (Note that stdbool.h
187-
* makes bool a macro, but our own replacement is a typedef, so the undef
188-
* makes ours visible again).
189-
*/
190-
#ifndefPG_USE_STDBOOL
191-
#ifdefbool
192-
#undef bool
193-
#endif
194-
#endif
195-
196177
/* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */
197178
#ifndefHeUTF8
198179
#defineHeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp