diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-09-12 17:35:55 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-09-12 17:36:26 +0200 |
commit | 595836e99bf1ee6d43405b885fb69bb8c6d3ee23 (patch) | |
tree | 9af38bcdaab9e75913c66b29f30caf1f9f4e5409 /src/include/utils/numeric.h | |
parent | 8cb2a22bbb2cf4212482ac15021ceaa2e9c52209 (diff) |
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.
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
Diffstat (limited to 'src/include/utils/numeric.h')
-rw-r--r-- | src/include/utils/numeric.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h index 3caa74dfe7a..88c62c5348b 100644 --- a/src/include/utils/numeric.h +++ b/src/include/utils/numeric.h @@ -56,9 +56,24 @@ typedef struct NumericData *Numeric; * fmgr interface macros */ -#define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X)) -#define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X)) -#define NumericGetDatum(X) PointerGetDatum(X) +static inline Numeric +DatumGetNumeric(Datum X) +{ + return (Numeric) PG_DETOAST_DATUM(X); +} + +static inline Numeric +DatumGetNumericCopy(Datum X) +{ + return (Numeric) PG_DETOAST_DATUM_COPY(X); +} + +static inline Datum +NumericGetDatum(Numeric X) +{ + return PointerGetDatum(X); +} + #define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n)) #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n)) #define PG_RETURN_NUMERIC(x) return NumericGetDatum(x) |