diff options
author | Thomas Munro <tmunro@postgresql.org> | 2024-11-28 11:48:07 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2024-11-28 12:01:14 +1300 |
commit | 97525bc5c8ffb31475d23955d08e9ec9c1408f33 (patch) | |
tree | 91a97f0167ef59db85c329f3bc4c3e973226ed50 /src/pl/plperl | |
parent | 4b03a27fafc98e2a34e4e0b5ca44895211e021cc (diff) | |
download | postgresql-97525bc5c8ffb31475d23955d08e9ec9c1408f33.tar.gz postgresql-97525bc5c8ffb31475d23955d08e9ec9c1408f33.zip |
Require sizeof(bool) == 1.
The C standard says that sizeof(bool) is implementation-defined, but we
know of no current systems where it is not 1. The last known systems
seem 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 of
bool that it used, but previously it would define its own type if the
system-provided bool had a different size. That was liable to cause
memory layout problems when interacting with system and third-party
libraries on (by now hypothetical) computers with wider _Bool, and now
C23 has introduced a new problem by making bool a built-in datatype
(like C++), so the fallback code doesn't even compile. We could
probably work around that, but then we'd be writing new untested code
for a computer that doesn't exist.
Instead, delete the unreachable and C23-uncompilable fallback code, and
let existing static assertions fail if the system-provided bool is too
wide. If we ever get a problem report from a real system, then it will
be time to figure out what to do about it in a way that also works on
modern compilers.
Note on C++: Previously we avoided including <stdbool.h> or trying to
define 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. We
already include <stdint.h> without C++ guards in c.h, and that falls
under 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
Diffstat (limited to 'src/pl/plperl')
-rw-r--r-- | src/pl/plperl/plperl_system.h | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/src/pl/plperl/plperl_system.h b/src/pl/plperl/plperl_system.h index 48f6575e513..d1b9ea17fca 100644 --- a/src/pl/plperl/plperl_system.h +++ b/src/pl/plperl/plperl_system.h @@ -72,16 +72,10 @@ #endif /* - * Regarding bool, both PostgreSQL and Perl might use stdbool.h or not, - * depending on configuration. If both agree, things are relatively harmless. - * If not, things get tricky. If PostgreSQL does but Perl does not, define - * HAS_BOOL here so that Perl does not redefine bool; this avoids compiler - * warnings. If PostgreSQL does not but Perl does, we need to undefine bool - * after we include the Perl headers; see below. + * Define HAS_BOOL here so that Perl does not redefine bool. We included + * <stdbool.h> in c.h. */ -#ifdef PG_USE_STDBOOL #define HAS_BOOL 1 -#endif /* * Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code @@ -180,19 +174,6 @@ /* perl version and platform portability */ #include "ppport.h" -/* - * perl might have included stdbool.h. If we also did that earlier (see c.h), - * then that's fine. If not, we probably rejected it for some reason. In - * that case, undef bool and proceed with our own bool. (Note that stdbool.h - * makes bool a macro, but our own replacement is a typedef, so the undef - * makes ours visible again). - */ -#ifndef PG_USE_STDBOOL -#ifdef bool -#undef bool -#endif -#endif - /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */ #ifndef HeUTF8 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \ |