summaryrefslogtreecommitdiff
path: root/src/include/tsearch
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/tsearch
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 <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/tsearch')
-rw-r--r--src/include/tsearch/ts_type.h46
-rw-r--r--src/include/tsearch/ts_utils.h14
2 files changed, 50 insertions, 10 deletions
diff --git a/src/include/tsearch/ts_type.h b/src/include/tsearch/ts_type.h
index 689b2d1cfb6..f1ec84702dc 100644
--- a/src/include/tsearch/ts_type.h
+++ b/src/include/tsearch/ts_type.h
@@ -111,12 +111,27 @@ typedef TSVectorData *TSVector;
#define POSDATAPTR(x,e) (_POSVECPTR(x,e)->pos)
/*
- * fmgr interface macros
+ * fmgr interface functions
*/
-#define DatumGetTSVector(X) ((TSVector) PG_DETOAST_DATUM(X))
-#define DatumGetTSVectorCopy(X) ((TSVector) PG_DETOAST_DATUM_COPY(X))
-#define TSVectorGetDatum(X) PointerGetDatum(X)
+static inline TSVector
+DatumGetTSVector(Datum X)
+{
+ return (TSVector) PG_DETOAST_DATUM(X);
+}
+
+static inline TSVector
+DatumGetTSVectorCopy(Datum X)
+{
+ return (TSVector) PG_DETOAST_DATUM_COPY(X);
+}
+
+static inline Datum
+TSVectorGetDatum(const TSVectorData *X)
+{
+ return PointerGetDatum(X);
+}
+
#define PG_GETARG_TSVECTOR(n) DatumGetTSVector(PG_GETARG_DATUM(n))
#define PG_GETARG_TSVECTOR_COPY(n) DatumGetTSVectorCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_TSVECTOR(x) return TSVectorGetDatum(x)
@@ -227,14 +242,29 @@ typedef TSQueryData *TSQuery;
#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem) )
/*
- * fmgr interface macros
+ * fmgr interface functions
* Note, TSQuery type marked as plain storage, so it can't be toasted
* but PG_DETOAST_DATUM_COPY is used for simplicity
*/
-#define DatumGetTSQuery(X) ((TSQuery) DatumGetPointer(X))
-#define DatumGetTSQueryCopy(X) ((TSQuery) PG_DETOAST_DATUM_COPY(X))
-#define TSQueryGetDatum(X) PointerGetDatum(X)
+static inline TSQuery
+DatumGetTSQuery(Datum X)
+{
+ return (TSQuery) DatumGetPointer(X);
+}
+
+static inline TSQuery
+DatumGetTSQueryCopy(Datum X)
+{
+ return (TSQuery) PG_DETOAST_DATUM_COPY(X);
+}
+
+static inline Datum
+TSQueryGetDatum(const TSQueryData *X)
+{
+ return PointerGetDatum(X);
+}
+
#define PG_GETARG_TSQUERY(n) DatumGetTSQuery(PG_GETARG_DATUM(n))
#define PG_GETARG_TSQUERY_COPY(n) DatumGetTSQueryCopy(PG_GETARG_DATUM(n))
#define PG_RETURN_TSQUERY(x) return TSQueryGetDatum(x)
diff --git a/src/include/tsearch/ts_utils.h b/src/include/tsearch/ts_utils.h
index fd73b384407..6fdd334fff4 100644
--- a/src/include/tsearch/ts_utils.h
+++ b/src/include/tsearch/ts_utils.h
@@ -243,8 +243,18 @@ typedef uint64 TSQuerySign;
#define TSQS_SIGLEN (sizeof(TSQuerySign)*BITS_PER_BYTE)
-#define TSQuerySignGetDatum(X) Int64GetDatum((int64) (X))
-#define DatumGetTSQuerySign(X) ((TSQuerySign) DatumGetInt64(X))
+static inline Datum
+TSQuerySignGetDatum(TSQuerySign X)
+{
+ return Int64GetDatum((int64) X);
+}
+
+static inline TSQuerySign
+DatumGetTSQuerySign(Datum X)
+{
+ return (TSQuerySign) DatumGetInt64(X);
+}
+
#define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X)
#define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n))