summaryrefslogtreecommitdiff
path: root/src/include/utils/varbit.h
diff options
context:
space:
mode:
authorPeter Eisentraut2022-09-27 18:47:07 +0000
committerPeter Eisentraut2022-09-27 18:50:21 +0000
commitc8b2ef05f481ef06326d7b9f3eb14b303f215c7e (patch)
tree5f72d0b7ee1eebd619c1b91b25f9a35a98f9218f /src/include/utils/varbit.h
parent8caf96de0b7b4ad5beb02b36a158196520c035a7 (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. 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 <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
Diffstat (limited to 'src/include/utils/varbit.h')
-rw-r--r--src/include/utils/varbit.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/include/utils/varbit.h b/src/include/utils/varbit.h
index 039ba860cfc..e65e7f65e7e 100644
--- a/src/include/utils/varbit.h
+++ b/src/include/utils/varbit.h
@@ -41,9 +41,24 @@ typedef struct
* BIT and BIT VARYING are toastable varlena types. They are the same
* as far as representation goes, so we just have one set of macros.
*/
-#define DatumGetVarBitP(X) ((VarBit *) PG_DETOAST_DATUM(X))
-#define DatumGetVarBitPCopy(X) ((VarBit *) PG_DETOAST_DATUM_COPY(X))
-#define VarBitPGetDatum(X) PointerGetDatum(X)
+static inline VarBit *
+DatumGetVarBitP(Datum X)
+{
+ return (VarBit *) PG_DETOAST_DATUM(X);
+}
+
+static inline VarBit *
+DatumGetVarBitPCopy(Datum X)
+{
+ return (VarBit *) PG_DETOAST_DATUM_COPY(X);
+}
+
+static inline Datum
+VarBitPGetDatum(const VarBit *X)
+{
+ return PointerGetDatum(X);
+}
+
#define PG_GETARG_VARBIT_P(n) DatumGetVarBitP(PG_GETARG_DATUM(n))
#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_VARBIT_P(x) return VarBitPGetDatum(x)