Thread

  1. [PATCH v5 3/4] Make casting between bool and GinTernaryValue more robust

    Peter Eisentraut <peter_e@gmx.net> — 2017-08-16T04:22:32Z

    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
    
    
    --------------AB99891BACB265862555DF3C
    Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0";
     name="v5-0004-Use-stdbool.h-if-available.patch"
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment;
     filename="v5-0004-Use-stdbool.h-if-available.patch"