From eba0febb6afc8b01dad80fecce222a0ac5dd6c85 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 16 Aug 2017 00:22:32 -0400 Subject: [PATCH v3 8/9] Make casting between bool and GinTernaryValue more robust These two types are both defined as char and are supposed to be castable to each other. But when stdbool.h is used, this is not guaranteed. So add provisions for different sizes of bool and define GinTernaryValue accordingly. --- src/backend/utils/adt/tsginidx.c | 2 +- src/include/access/gin.h | 14 ++++++++++---- src/include/c.h | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c index aba456ed88..fa792b84dc 100644 --- a/src/backend/utils/adt/tsginidx.c +++ b/src/backend/utils/adt/tsginidx.c @@ -309,7 +309,7 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS) * query. */ gcv.first_item = GETQUERY(query); - gcv.check = check; + gcv.check = (GinTernaryValue *) check; gcv.map_item_operand = (int *) (extra_data[0]); gcv.need_recheck = recheck; diff --git a/src/include/access/gin.h b/src/include/access/gin.h index ec83058095..d58af1d6a1 100644 --- a/src/include/access/gin.h +++ b/src/include/access/gin.h @@ -51,14 +51,20 @@ typedef struct GinStatsData /* * A ternary value used by tri-consistent functions. * - * For convenience, this is compatible with booleans. A boolean can be + * For convenience, this is compatible with bools. A bool can be * safely cast to a GinTernaryValue. */ +#if SIZEOF_BOOL == 1 typedef char GinTernaryValue; +#elif SIZEOF_BOOL == 4 +typedef int GinTernaryValue; +#else +#error unsupported SIZEOF_BOOL +#endif -#define GIN_FALSE 0 /* item is not present / does not match */ -#define GIN_TRUE 1 /* item is present / matches */ -#define GIN_MAYBE 2 /* don't know if item is present / don't know +#define GIN_FALSE ((GinTernaryValue) 0) /* item is not present / does not match */ +#define GIN_TRUE ((GinTernaryValue) 1) /* item is present / matches */ +#define GIN_MAYBE ((GinTernaryValue) 2) /* don't know if item is present / don't know * if matches */ #define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X)) diff --git a/src/include/c.h b/src/include/c.h index 3968af234f..9bf369bd1f 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -200,6 +200,7 @@ #ifndef bool typedef char bool; +#define SIZEOF_BOOL 1 #endif #ifndef true -- 2.14.3