Re: GinPageIs* don't actually return a boolean - Mailing list pgsql-hackers

From Tom Lane
Subject Re: GinPageIs* don't actually return a boolean
Date
Msg-id 23420.1439311231@sss.pgh.pa.us
Whole thread Raw
In response to GinPageIs* don't actually return a boolean  (Andres Freund <andres@anarazel.de>)
Responses Re: GinPageIs* don't actually return a boolean  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> #define GinPageIsLeaf(page)    ( GinPageGetOpaque(page)->flags & GIN_LEAF )
> #define GinPageIsData(page)    ( GinPageGetOpaque(page)->flags & GIN_DATA )
> #define GinPageIsList(page)    ( GinPageGetOpaque(page)->flags & GIN_LIST )

> These macros don't actually return a boolean that's comparable with our
> true/false. That doesn't strike me as a good idea.

Agreed, this is risky.  For example, if the bit being tested is to the
left of the lowest byte of "flags", storing the result into a bool
variable would do the wrong thing.

> I think we should add a !! to these macros to make sure it's an actual
> boolean.

Please write it more like

#define GinPageIsLeaf(page)  ((GinPageGetOpaque(page)->flags & GIN_LEAF) != 0)

We do not use !! elsewhere for this purpose, and I for one find it a
pretty ugly locution.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: WIP: SCRAM authentication
Next
From: Robert Haas
Date:
Subject: Re: GinPageIs* don't actually return a boolean