diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-09-27 20:47:07 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-09-27 20:50:21 +0200 |
commit | c8b2ef05f481ef06326d7b9f3eb14b303f215c7e (patch) | |
tree | 5f72d0b7ee1eebd619c1b91b25f9a35a98f9218f /src/include/utils/rangetypes.h | |
parent | 8caf96de0b7b4ad5beb02b36a158196520c035a7 (diff) | |
download | postgresql-c8b2ef05f481ef06326d7b9f3eb14b303f215c7e.tar.gz |
Convert *GetDatum() and DatumGet*() macros to inline functions
The previous macro implementations just cast the argument to a target
type but did not check whether the input type was appropriate. The
function implementation can do better type checking of the input type.
For the *GetDatumFast() macros, converting to an inline function
doesn't work in the !USE_FLOAT8_BYVAL case, but we can use
AssertVariableIsOfTypeMacro() to get a similar level of type checking.
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
Diffstat (limited to 'src/include/utils/rangetypes.h')
-rw-r--r-- | src/include/utils/rangetypes.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/include/utils/rangetypes.h b/src/include/utils/rangetypes.h index b62f1ea481..2eee6a6c1f 100644 --- a/src/include/utils/rangetypes.h +++ b/src/include/utils/rangetypes.h @@ -68,11 +68,26 @@ typedef struct } RangeBound; /* - * fmgr macros for range type objects + * fmgr functions for range type objects */ -#define DatumGetRangeTypeP(X) ((RangeType *) PG_DETOAST_DATUM(X)) -#define DatumGetRangeTypePCopy(X) ((RangeType *) PG_DETOAST_DATUM_COPY(X)) -#define RangeTypePGetDatum(X) PointerGetDatum(X) +static inline RangeType * +DatumGetRangeTypeP(Datum X) +{ + return (RangeType *) PG_DETOAST_DATUM(X); +} + +static inline RangeType * +DatumGetRangeTypePCopy(Datum X) +{ + return (RangeType *) PG_DETOAST_DATUM_COPY(X); +} + +static inline Datum +RangeTypePGetDatum(const RangeType *X) +{ + return PointerGetDatum(X); +} + #define PG_GETARG_RANGE_P(n) DatumGetRangeTypeP(PG_GETARG_DATUM(n)) #define PG_GETARG_RANGE_P_COPY(n) DatumGetRangeTypePCopy(PG_GETARG_DATUM(n)) #define PG_RETURN_RANGE_P(x) return RangeTypePGetDatum(x) |