From ba713e6c1d85f59b421630c4698e1558fe323ed2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 16 Aug 2017 00:22:32 -0400 Subject: [PATCH v5 3/4] 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 | 8 +++++++- src/include/c.h | 1 + 3 files changed, 9 insertions(+), 2 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..fd4880a7f7 100644 --- a/src/include/access/gin.h +++ b/src/include/access/gin.h @@ -51,10 +51,16 @@ 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 */ diff --git a/src/include/c.h b/src/include/c.h index 20c15a0d9d..1d656e37d5 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -255,6 +255,7 @@ #ifndef bool typedef char bool; +#define SIZEOF_BOOL 1 #endif #ifndef true -- 2.15.1