Re: [HACKERS] taking stdbool.h into use
Michael Paquier <michael.paquier@gmail.com>
From: Michael Paquier <michael.paquier@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Thomas Munro <thomas.munro@enterprisedb.com>
Date: 2018-01-09T05:17:53Z
Lists: pgsql-hackers
On Sat, Dec 30, 2017 at 10:31:45AM -0500, Tom Lane wrote: > Surely bool and bool8 should have identical Datum representations, > so I'm not sure they need different DatumGet/GetDatum macros. [... refresh update ...] Yeah sure. I am a bit disturbed by the fact that DatumGetBool() enforces a case to bool though. > Although this opens up another point: just above those macros, > postgres.h says > > * When a type narrower than Datum is stored in a Datum, we place it in the > * low-order bits and are careful that the DatumGetXXX macro for it discards > * the unused high-order bits (as opposed to, say, assuming they are zero). > * This is needed to support old-style user-defined functions, since depending > * on architecture and compiler, the return value of a function returning char > * or short may contain garbage when called as if it returned Datum. > > Since we flushed support for V0 functions, the stated rationale doesn't > apply anymore. I wonder whether there is anything to be gained by > changing DatumGetXXX and XXXGetDatum to be simple casts (as, if memory > serves, they once were until we noticed the stated hazard). Or, if > there's still a reason to keep the masking steps in place, we'd better > update this comment. 23a41573 did not do it rightly visibly, and 23b09e1 got it better, still GET_1_BYTE() was getting used only because of V0 functions being used in contrib/seg and because of the way MSVC 2015 handles boolean evaluation as per thread [1]. In short, your argument for a switch to simple casts makes sense for me. [1]: https://www.postgresql.org/message-id/E1atdPs-0005zu-Re@gemulon.postgresql.org -- Michael
Commits
-
Use stdbool.h if suitable
- 9a95a77d9d5d 11.0 landed
-
Add configure tests for stdbool.h and sizeof bool
- f20b3285340c 11.0 landed
-
Remove useless use of bit-masking macros
- d91da5ecedc8 11.0 landed
-
Change various Gin*Is* macros to return 0/1.
- af4472bcb88a 9.6.0 cited
-
Fix several possibly non-portable gaffs in record_image_ops.
- 4cbb646334b3 9.4.0 cited