diff --git a/src/btree_rum.c b/src/btree_rum.c index dd43a3c037..f4acb174a1 100644 --- a/src/btree_rum.c +++ b/src/btree_rum.c @@ -17,6 +17,27 @@ #include "rum.h" +/* + * PostgreSQL's own fallthrough-attribute wrapper is not a stable target: + * it's pg_attribute_fallthrough() (function-call-style) through PG18, + * pg_fallthrough (a bare, parenless macro) from PG19 on -- and even on + * PG18, pg_attribute_fallthrough() is not reliably declared under every + * compiler/build-mode combination (e.g. it's missing under clang's + * -emit-llvm JIT bitcode pass). Rather than keep chasing PostgreSQL's + * internal macro across versions and compilers, detect compiler support + * for the attribute directly and supply our own wrapper. This matches + * exactly what PostgreSQL's own macros expand to, just without relying + * on PostgreSQL to declare it consistently. + */ +#if defined(__has_attribute) +#if __has_attribute(fallthrough) +#define RUM_FALLTHROUGH() __attribute__((fallthrough)) +#endif +#endif +#ifndef RUM_FALLTHROUGH +#define RUM_FALLTHROUGH() ((void) 0) +#endif + #if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1800 // Between VC++ 6.0 and VC++ 11.0 #include #define isfinite _finite @@ -112,7 +133,7 @@ rum_btree_extract_query(FunctionCallInfo fcinfo, case BTGreaterEqualStrategyNumber: case BTGreaterStrategyNumber: *ptr_partialmatch = true; - /*FALLTHROUGH*/ + RUM_FALLTHROUGH(); case BTEqualStrategyNumber: case RUM_DISTANCE: case RUM_LEFT_DISTANCE: diff --git a/src/rum.h b/src/rum.h index 7093c4082c..9b0106abbe 100644 --- a/src/rum.h +++ b/src/rum.h @@ -1019,7 +1019,15 @@ rumDataPageLeafRead(char *ptr, OffsetNumber attnum, RumItem * item, switch (attr->attlen) { case sizeof(char): - item->addInfo = Int8GetDatum(*ptr); + + /* + * PG19 removed Int8GetDatum() from postgres.h. + * CharGetDatum() performs the identical (Datum) (X) + * byte-value conversion and remains present in every + * supported PostgreSQL version, so use it instead of + * depending on Int8GetDatum()'s continued existence. + */ + item->addInfo = CharGetDatum(*ptr); break; case sizeof(int16): memcpy(&u.i16, ptr, sizeof(int16)); diff --git a/src/rumutil.c b/src/rumutil.c index 53a8667207..bef8436d01 100644 --- a/src/rumutil.c +++ b/src/rumutil.c @@ -284,6 +284,20 @@ initRumState(RumState * state, Relation index) { state->addAttrs[i] = NULL; } + + /* + * PG19 added a tuple-deformation offset cache to TupleDesc + * (firstNonCachedOffsetAttr) that is only initialized by + * TupleDescFinalize(). Any TupleDesc hand-built via + * CreateTemplateTupleDesc()/TupleDescInitEntry(), as above, + * must now be finalized before it is used to form or read + * tuples, or PG core will hit + * Assert(tupleDesc->firstNonCachedOffsetAttr >= 0) the first + * time it tries to deform one -- exactly what happened here. + */ +#if PG_VERSION_NUM >= 190000 + TupleDescFinalize(state->tupdesc[i]); +#endif } else { @@ -311,6 +325,11 @@ initRumState(RumState * state, Relation index) { state->addAttrs[i] = NULL; } + + /* See comment above the oneCol branch's TupleDescFinalize(). */ +#if PG_VERSION_NUM >= 190000 + TupleDescFinalize(state->tupdesc[i]); +#endif } /*