Avoid unsatisfied-external-reference errors in static inlines.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 13 Jul 2022 17:37:10 +0000 (13:37 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 13 Jul 2022 17:37:10 +0000 (13:37 -0400)
Commit 9c727360b neglected the lesson we've learned before:
protect references to backend global variables with #ifndef FRONTEND.

Since there's already a place for static inlines in this file,
move the just-converted functions to that stanza.  Undo the
entirely gratuitous de-macroization of RelationGetNumberOfBlocks
(that one may be okay, since it has no global variable references,
but it's also pointless).

Per buildfarm.

src/include/storage/bufmgr.h

index f7fc60815a651a3b725db695ded26eeaea35cfc5..bf8cce7ccf6d59fd89e76e3aec795e59f3b68c1f 100644 (file)
@@ -97,86 +97,6 @@ extern PGDLLIMPORT int32 *LocalRefCount;
 #define BUFFER_LOCK_SHARE              1
 #define BUFFER_LOCK_EXCLUSIVE  2
 
-/*
- * These routines are beaten on quite heavily, hence inline.
- */
-
-/*
- * BufferIsValid
- *             True iff the given buffer number is valid (either as a shared
- *             or local buffer).
- *
- * Note: For a long time this was defined the same as BufferIsPinned,
- * that is it would say False if you didn't hold a pin on the buffer.
- * I believe this was bogus and served only to mask logic errors.
- * Code should always know whether it has a buffer reference,
- * independently of the pin state.
- *
- * Note: For a further long time this was not quite the inverse of the
- * BufferIsInvalid() macro, in that it also did sanity checks to verify
- * that the buffer number was in range.  Most likely, this macro was
- * originally intended only to be used in assertions, but its use has
- * since expanded quite a bit, and the overhead of making those checks
- * even in non-assert-enabled builds can be significant.  Thus, we've
- * now demoted the range checks to assertions within the macro itself.
- */
-static inline bool
-BufferIsValid(Buffer bufnum)
-{
-       Assert(bufnum <= NBuffers);
-       Assert(bufnum >= -NLocBuffer);
-
-       return bufnum != InvalidBuffer;
-}
-
-/*
- * BufferGetBlock
- *             Returns a reference to a disk page image associated with a buffer.
- *
- * Note:
- *             Assumes buffer is valid.
- */
-static inline Block
-BufferGetBlock(Buffer buffer)
-{
-       Assert(BufferIsValid(buffer));
-
-       if (BufferIsLocal(buffer))
-               return LocalBufferBlockPointers[-buffer - 1];
-       else
-               return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
-}
-
-/*
- * BufferGetPageSize
- *             Returns the page size within a buffer.
- *
- * Notes:
- *             Assumes buffer is valid.
- *
- *             The buffer can be a raw disk block and need not contain a valid
- *             (formatted) disk page.
- */
-/* XXX should dig out of buffer descriptor */
-static inline Size
-BufferGetPageSize(Buffer buffer)
-{
-       AssertMacro(BufferIsValid(buffer));
-       return (Size) BLCKSZ;
-}
-
-/*
- * BufferGetPage
- *             Returns the page associated with a buffer.
- *
- * When this is called as part of a scan, there may be a need for a nearby
- * call to TestForOldSnapshot().  See the definition of that for details.
- */
-static inline Page
-BufferGetPage(Buffer buffer)
-{
-       return (Page) BufferGetBlock(buffer);
-}
 
 /*
  * prototypes for functions in bufmgr.c
@@ -211,12 +131,6 @@ extern void CheckPointBuffers(int flags);
 extern BlockNumber BufferGetBlockNumber(Buffer buffer);
 extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
                                                                                                   ForkNumber forkNum);
-static inline BlockNumber
-RelationGetNumberOfBlocks(Relation reln)
-{
-       return RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM);
-}
-
 extern void FlushOneBuffer(Buffer buffer);
 extern void FlushRelationBuffers(Relation rel);
 extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels);
@@ -231,6 +145,9 @@ extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
                                                                        int nlocators);
 extern void DropDatabaseBuffers(Oid dbid);
 
+#define RelationGetNumberOfBlocks(reln) \
+       RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
+
 extern bool BufferIsPermanent(Buffer buffer);
 extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
 
@@ -276,6 +193,83 @@ extern void FreeAccessStrategy(BufferAccessStrategy strategy);
 
 #ifndef FRONTEND
 
+/*
+ * BufferIsValid
+ *             True iff the given buffer number is valid (either as a shared
+ *             or local buffer).
+ *
+ * Note: For a long time this was defined the same as BufferIsPinned,
+ * that is it would say False if you didn't hold a pin on the buffer.
+ * I believe this was bogus and served only to mask logic errors.
+ * Code should always know whether it has a buffer reference,
+ * independently of the pin state.
+ *
+ * Note: For a further long time this was not quite the inverse of the
+ * BufferIsInvalid() macro, in that it also did sanity checks to verify
+ * that the buffer number was in range.  Most likely, this macro was
+ * originally intended only to be used in assertions, but its use has
+ * since expanded quite a bit, and the overhead of making those checks
+ * even in non-assert-enabled builds can be significant.  Thus, we've
+ * now demoted the range checks to assertions within the macro itself.
+ */
+static inline bool
+BufferIsValid(Buffer bufnum)
+{
+       Assert(bufnum <= NBuffers);
+       Assert(bufnum >= -NLocBuffer);
+
+       return bufnum != InvalidBuffer;
+}
+
+/*
+ * BufferGetBlock
+ *             Returns a reference to a disk page image associated with a buffer.
+ *
+ * Note:
+ *             Assumes buffer is valid.
+ */
+static inline Block
+BufferGetBlock(Buffer buffer)
+{
+       Assert(BufferIsValid(buffer));
+
+       if (BufferIsLocal(buffer))
+               return LocalBufferBlockPointers[-buffer - 1];
+       else
+               return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
+}
+
+/*
+ * BufferGetPageSize
+ *             Returns the page size within a buffer.
+ *
+ * Notes:
+ *             Assumes buffer is valid.
+ *
+ *             The buffer can be a raw disk block and need not contain a valid
+ *             (formatted) disk page.
+ */
+/* XXX should dig out of buffer descriptor */
+static inline Size
+BufferGetPageSize(Buffer buffer)
+{
+       AssertMacro(BufferIsValid(buffer));
+       return (Size) BLCKSZ;
+}
+
+/*
+ * BufferGetPage
+ *             Returns the page associated with a buffer.
+ *
+ * When this is called as part of a scan, there may be a need for a nearby
+ * call to TestForOldSnapshot().  See the definition of that for details.
+ */
+static inline Page
+BufferGetPage(Buffer buffer)
+{
+       return (Page) BufferGetBlock(buffer);
+}
+
 /*
  * Check whether the given snapshot is too old to have safely read the given
  * page from the given table.  If so, throw a "snapshot too old" error.