Re: GinPageIs* don't actually return a boolean

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: GinPageIs* don't actually return a boolean
Дата
Msg-id 23420.1439311231@sss.pgh.pa.us
обсуждение исходный текст
Ответ на GinPageIs* don't actually return a boolean  (Andres Freund <andres@anarazel.de>)
Ответы Re: GinPageIs* don't actually return a boolean  (Robert Haas <robertmhaas@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: WIP: SCRAM authentication
Следующее
От: Robert Haas
Дата:
Сообщение: Re: GinPageIs* don't actually return a boolean