Make verify_compact_attribute available in non-assert builds
authorDavid Rowley <[email protected]>
Sat, 11 Jan 2025 00:45:54 +0000 (13:45 +1300)
committerDavid Rowley <[email protected]>
Sat, 11 Jan 2025 00:45:54 +0000 (13:45 +1300)
6f3820f37 adjusted the assert-enabled validation of the CompactAttribute
to call a new external function to perform the validation.  That commit
made it so the function was only available when building with
USE_ASSERT_CHECKING, and because TupleDescCompactAttr() is a static
inline function, the call to verify_compact_attribute() was compiled
into any extension which uses TupleDescCompactAttr().  This caused issues
for such extensions when loading the assert-enabled extension into
PostgreSQL versions without asserts enabled due to that function being
unavailable in core.

To fix this, make verify_compact_attribute() available unconditionally,
but make it do nothing unless building with USE_ASSERT_CHECKING.

Author: Andrew Kane <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAOdR5yHfMEMW00XGo=v1zCVUS6Huq2UehXdvKnwtXPTcZwXhmg@mail.gmail.com

src/backend/access/common/tupdesc.c
src/include/access/tupdesc.h

index cc940742197351108a5c08f3ff470b73c4c7ad01..2e4666c469cc7ca958fcc4f53ffe8736b2f1121f 100644 (file)
@@ -118,7 +118,6 @@ populate_compact_attribute(TupleDesc tupdesc, int attnum)
    populate_compact_attribute_internal(src, dst);
 }
 
-#ifdef USE_ASSERT_CHECKING
 /*
  * verify_compact_attribute
  *     In Assert enabled builds, we verify that the CompactAttribute is
@@ -132,6 +131,7 @@ populate_compact_attribute(TupleDesc tupdesc, int attnum)
 void
 verify_compact_attribute(TupleDesc tupdesc, int attnum)
 {
+#ifdef USE_ASSERT_CHECKING
    CompactAttribute *cattr = &tupdesc->compact_attrs[attnum];
    Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum);
    CompactAttribute tmp;
@@ -150,9 +150,8 @@ verify_compact_attribute(TupleDesc tupdesc, int attnum)
 
    /* Check the freshly populated CompactAttribute matches the TupleDesc's */
    Assert(memcmp(&tmp, cattr, sizeof(CompactAttribute)) == 0);
-}
 #endif
-
+}
 
 /*
  * CreateTemplateTupleDesc
index aee871b0e8f7d73c14e0e07073dc3cecfe5fe430..504ce22250034bf31442f0bafe203993d7438821 100644 (file)
@@ -158,9 +158,7 @@ TupleDescAttr(TupleDesc tupdesc, int i)
 
 #undef TupleDescAttrAddress
 
-#ifdef USE_ASSERT_CHECKING
 extern void verify_compact_attribute(TupleDesc, int attnum);
-#endif
 
 /*
  * Accessor for the i'th CompactAttribute element of tupdesc.