summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorPeter Eisentraut2018-03-23 00:42:25 +0000
committerPeter Eisentraut2018-03-23 00:42:25 +0000
commit9a95a77d9d5d3003d2d67121f2731b6e5fc37336 (patch)
tree1f43f5ff016c3ee689c09030000c4a0e8bc25842 /src/include
parent2a0faed9d7028e3830998bd6ca900be651274e27 (diff)
Use stdbool.h if suitable
Using the standard bool type provided by C allows some recent compilers and debuggers to give better diagnostics. Also, some extension code and third-party headers are increasingly pulling in stdbool.h, so it's probably saner if everyone uses the same definition. But PostgreSQL code is not prepared to handle bool of a size other than 1, so we keep our own old definition if we encounter a stdbool.h with a bool of a different size. (Among current build farm members, this only applies to old macOS versions on PowerPC.) To check that the used bool is of the right size, add a static assertions about size of GinTernaryValue vs bool. This is currently the only place that assumes that bool and char are of the same size. Discussion: https://www.postgresql.org/message-id/flat/3a0fe7e1-5ed1-414b-9230-53bbc0ed1f49@2ndquadrant.com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/gin.h4
-rw-r--r--src/include/c.h14
-rw-r--r--src/include/pg_config.h.win329
3 files changed, 23 insertions, 4 deletions
diff --git a/src/include/access/gin.h b/src/include/access/gin.h
index 0acdb88241e..3d8a130b69b 100644
--- a/src/include/access/gin.h
+++ b/src/include/access/gin.h
@@ -51,8 +51,8 @@ typedef struct GinStatsData
/*
* A ternary value used by tri-consistent functions.
*
- * For convenience, this is compatible with booleans. A boolean can be
- * safely cast to a GinTernaryValue.
+ * This must be of the same size as a bool because some code will cast a
+ * pointer to a bool to a pointer to a GinTernaryValue.
*/
typedef char GinTernaryValue;
diff --git a/src/include/c.h b/src/include/c.h
index 37c0c391990..107f4f6bcd7 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -255,12 +255,21 @@
* bool
* Boolean value, either true or false.
*
- * XXX for C++ compilers, we assume the compiler has a compatible
- * built-in definition of bool.
+ * Use stdbool.h if available and its bool has size 1. That's useful for
+ * better compiler and debugger output and for compatibility with third-party
+ * libraries. But PostgreSQL currently cannot deal with bool of other sizes;
+ * there are static assertions around the code to prevent that.
+ *
+ * For C++ compilers, we assume the compiler has a compatible built-in
+ * definition of bool.
*/
#ifndef __cplusplus
+#if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL == 1
+#include <stdbool.h>
+#else
+
#ifndef bool
typedef char bool;
#endif
@@ -273,6 +282,7 @@ typedef char bool;
#define false ((bool) 0)
#endif
+#endif
#endif /* not C++ */
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index e934cf87bd2..b0477f02311 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -356,6 +356,9 @@
/* Define to 1 if you have the `SSL_get_current_compression' function. */
#define HAVE_SSL_GET_CURRENT_COMPRESSION 1
+/* Define to 1 if stdbool.h conforms to C99. */
+/* #undef HAVE_STDBOOL_H */
+
/* Define to 1 if you have the <stdint.h> header file. */
/* #undef HAVE_STDINT_H */
@@ -524,6 +527,9 @@
/* Define to 1 if you have the <winldap.h> header file. */
/* #undef HAVE_WINLDAP_H */
+/* Define to 1 if the system has the type `_Bool'. */
+/* #undef HAVE__BOOL */
+
/* Define to 1 if your compiler understands __builtin_bswap16. */
/* #undef HAVE__BUILTIN_BSWAP16 */
@@ -606,6 +612,9 @@
/* A string containing the version number, platform, and C compiler */
#define PG_VERSION_STR "Uninitialized version string (win32)"
+/* The size of `bool', as computed by sizeof. */
+#define SIZEOF_BOOL 0
+
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4