From b8f2c2f144c1763029ba8b84093a1885f57627a1 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 27 Dec 2024 11:07:35 +0100 Subject: [PATCH 3/3] WIP: Use some generic selection Use generic selection (C11 _Generic) to allow a few functions in htup_details.h to work with both HeapTuple and MinimalTuple. --- src/include/access/htup_details.h | 50 +++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h index bab480fe2f0..cb862ff089d 100644 --- a/src/include/access/htup_details.h +++ b/src/include/access/htup_details.h @@ -574,21 +574,23 @@ HeapTupleHeaderClearHeapOnly(HeapTupleHeaderData *tup) tup->t_infomask2 &= ~HEAP_ONLY_TUPLE; } -/* - * These are used with both HeapTuple and MinimalTuple, so they must be - * macros. - */ - -#define HeapTupleHeaderGetNatts(tup) \ - ((tup)->t_infomask2 & HEAP_NATTS_MASK) +static inline int +HeapTupleHeaderGetNatts(const HeapTupleHeaderData *tup) +{ + return tup->t_infomask2 & HEAP_NATTS_MASK; +} -#define HeapTupleHeaderSetNatts(tup, natts) \ -( \ - (tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \ -) +static inline void +HeapTupleHeaderSetNatts(HeapTupleHeaderData *tup, int natts) +{ + tup->t_infomask2 = (tup->t_infomask2 & ~HEAP_NATTS_MASK) | natts; +} -#define HeapTupleHeaderHasExternal(tup) \ - (((tup)->t_infomask & HEAP_HASEXTERNAL) != 0) +static inline bool +HeapTupleHeaderHasExternal(HeapTupleHeaderData *tup) +{ + return (tup->t_infomask & HEAP_HASEXTERNAL) != 0; +} /* @@ -725,6 +727,28 @@ HeapTupleHeaderClearMatch(MinimalTupleData *tup) tup->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH; } +/* + * Accessor functions for both HeapTupleHeader and MinimalTuple + */ + +static inline bool +MinimalTupleHasExternal(MinimalTupleData *tup) +{ + return (tup->t_infomask & HEAP_HASEXTERNAL) != 0; +} + +#define HeapTupleHeaderHasExternal(tup) \ + _Generic((tup), HeapTupleHeaderData*: HeapTupleHeaderHasExternal, MinimalTupleData*: MinimalTupleHasExternal)(tup) + +static inline void +MinimalTupleSetNatts(MinimalTupleData *tup, int natts) +{ + tup->t_infomask2 = (tup->t_infomask2 & ~HEAP_NATTS_MASK) | natts; +} + +#define HeapTupleHeaderSetNatts(tup, natts) \ + _Generic((tup), HeapTupleHeaderData*: HeapTupleHeaderSetNatts, MinimalTupleData*: MinimalTupleSetNatts)(tup, natts) + /* * GETSTRUCT - given a HeapTuple pointer, return address of the user data -- 2.47.1