diff options
| author | Thomas Munro | 2024-11-27 22:48:07 +0000 |
|---|---|---|
| committer | Thomas Munro | 2024-11-27 23:01:14 +0000 |
| commit | 97525bc5c8ffb31475d23955d08e9ec9c1408f33 (patch) | |
| tree | 91a97f0167ef59db85c329f3bc4c3e973226ed50 /src/interfaces/ecpg | |
| parent | 4b03a27fafc98e2a34e4e0b5ca44895211e021cc (diff) | |
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/interfaces/ecpg')
| -rw-r--r-- | src/interfaces/ecpg/include/ecpg_config.h.in | 3 | ||||
| -rw-r--r-- | src/interfaces/ecpg/include/ecpglib.h | 30 | ||||
| -rw-r--r-- | src/interfaces/ecpg/include/meson.build | 1 |
3 files changed, 1 insertions, 33 deletions
diff --git a/src/interfaces/ecpg/include/ecpg_config.h.in b/src/interfaces/ecpg/include/ecpg_config.h.in index 2b439c1e58d..75f542f263b 100644 --- a/src/interfaces/ecpg/include/ecpg_config.h.in +++ b/src/interfaces/ecpg/include/ecpg_config.h.in @@ -6,6 +6,3 @@ /* Define to 1 if `long long int' works and is 64 bits. */ #undef HAVE_LONG_LONG_INT_64 - -/* Define to 1 to use <stdbool.h> to define type bool. */ -#undef PG_USE_STDBOOL diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 771761ffe49..dbf3cc3a0c2 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -7,6 +7,7 @@ #ifndef _ECPGLIB_H #define _ECPGLIB_H +#include <stdbool.h> #include <string.h> #include "ecpg_config.h" @@ -14,35 +15,6 @@ #include "libpq-fe.h" #include "sqlca.h" -/* - * This is a small extract from c.h since we don't want to leak all postgres - * definitions into ecpg programs; but we need to know what bool is. - */ -#ifndef __cplusplus - -#ifdef PG_USE_STDBOOL -#include <stdbool.h> -#else - -/* - * We assume bool has been defined if true and false are. This avoids - * duplicate-typedef errors if this file is included after c.h. - */ -#if !(defined(true) && defined(false)) -typedef unsigned char bool; -#endif - -#ifndef true -#define true ((bool) 1) -#endif - -#ifndef false -#define false ((bool) 0) -#endif - -#endif /* not PG_USE_STDBOOL */ -#endif /* not C++ */ - #ifdef __cplusplus extern "C" diff --git a/src/interfaces/ecpg/include/meson.build b/src/interfaces/ecpg/include/meson.build index b4a5aedd51f..a3beb3cc7be 100644 --- a/src/interfaces/ecpg/include/meson.build +++ b/src/interfaces/ecpg/include/meson.build @@ -5,7 +5,6 @@ ecpg_inc = include_directories('.') ecpg_conf_keys = [ 'HAVE_LONG_INT_64', 'HAVE_LONG_LONG_INT_64', - 'PG_USE_STDBOOL', ] ecpg_conf_data = configuration_data() |
