mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
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
This commit is contained in:
@ -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)
|
||||
|
@ -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))
|
||||
|
||||
|
Reference in New Issue
Block a user