Consolidate ItemPointer to Datum conversion functions

Instead of defining the same set of macros several times, define it
once in an appropriate header file.  In passing, convert to inline
functions.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/844dd4c5-e5a1-3df1-bfaf-d1e1c2a16e45%40enterprisedb.com
This commit is contained in:
Peter Eisentraut 2023-02-13 09:50:14 +01:00
parent 7da51590ed
commit bd944884e9
5 changed files with 20 additions and 12 deletions

View File

@ -50,8 +50,6 @@ PG_FUNCTION_INFO_V1(bt_multi_page_stats);
#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X))
#define ItemPointerGetDatum(X) PointerGetDatum(X)
/* ------------------------------------------------
* structure for single btree page statistics

View File

@ -21,9 +21,6 @@
#include "utils/builtins.h"
#include "utils/rel.h"
#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X))
#define ItemPointerGetDatum(X) PointerGetDatum(X)
PG_FUNCTION_INFO_V1(gin_metapage_info);
PG_FUNCTION_INFO_V1(gin_page_opaque_info);

View File

@ -31,8 +31,6 @@ PG_FUNCTION_INFO_V1(gist_page_items_bytea);
#define IS_GIST(r) ((r)->rd_rel->relam == GIST_AM_OID)
#define ItemPointerGetDatum(X) PointerGetDatum(X)
Datum
gist_page_opaque_info(PG_FUNCTION_ARGS)

View File

@ -37,11 +37,6 @@
#include "utils/varlena.h"
#define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X))
#define ItemPointerGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_ITEMPOINTER(n) DatumGetItemPointer(PG_GETARG_DATUM(n))
#define PG_RETURN_ITEMPOINTER(x) return ItemPointerGetDatum(x)
#define LDELIM '('
#define RDELIM ')'
#define DELIM ','

View File

@ -222,4 +222,24 @@ extern int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2);
extern void ItemPointerInc(ItemPointer pointer);
extern void ItemPointerDec(ItemPointer pointer);
/* ----------------
* Datum conversion functions
* ----------------
*/
static inline ItemPointer
DatumGetItemPointer(Datum X)
{
return (ItemPointer) DatumGetPointer(X);
}
static inline Datum
ItemPointerGetDatum(const ItemPointerData *X)
{
return PointerGetDatum(X);
}
#define PG_GETARG_ITEMPOINTER(n) DatumGetItemPointer(PG_GETARG_DATUM(n))
#define PG_RETURN_ITEMPOINTER(x) return ItemPointerGetDatum(x)
#endif /* ITEMPTR_H */