Skip to content

Commit 27d2693

Browse files
committed
Avoid unsatisfied-external-reference errors in static inlines.
Commit 9c72736 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.
1 parent 617d691 commit 27d2693

File tree

1 file changed

+80
-86
lines changed

1 file changed

+80
-86
lines changed

src/include/storage/bufmgr.h

Lines changed: 80 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -97,86 +97,6 @@ extern PGDLLIMPORT int32 *LocalRefCount;
9797
#define BUFFER_LOCK_SHARE 1
9898
#define BUFFER_LOCK_EXCLUSIVE 2
9999

100-
/*
101-
* These routines are beaten on quite heavily, hence inline.
102-
*/
103-
104-
/*
105-
* BufferIsValid
106-
* True iff the given buffer number is valid (either as a shared
107-
* or local buffer).
108-
*
109-
* Note: For a long time this was defined the same as BufferIsPinned,
110-
* that is it would say False if you didn't hold a pin on the buffer.
111-
* I believe this was bogus and served only to mask logic errors.
112-
* Code should always know whether it has a buffer reference,
113-
* independently of the pin state.
114-
*
115-
* Note: For a further long time this was not quite the inverse of the
116-
* BufferIsInvalid() macro, in that it also did sanity checks to verify
117-
* that the buffer number was in range. Most likely, this macro was
118-
* originally intended only to be used in assertions, but its use has
119-
* since expanded quite a bit, and the overhead of making those checks
120-
* even in non-assert-enabled builds can be significant. Thus, we've
121-
* now demoted the range checks to assertions within the macro itself.
122-
*/
123-
static inline bool
124-
BufferIsValid(Buffer bufnum)
125-
{
126-
Assert(bufnum <= NBuffers);
127-
Assert(bufnum >= -NLocBuffer);
128-
129-
return bufnum != InvalidBuffer;
130-
}
131-
132-
/*
133-
* BufferGetBlock
134-
* Returns a reference to a disk page image associated with a buffer.
135-
*
136-
* Note:
137-
* Assumes buffer is valid.
138-
*/
139-
static inline Block
140-
BufferGetBlock(Buffer buffer)
141-
{
142-
Assert(BufferIsValid(buffer));
143-
144-
if (BufferIsLocal(buffer))
145-
return LocalBufferBlockPointers[-buffer - 1];
146-
else
147-
return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
148-
}
149-
150-
/*
151-
* BufferGetPageSize
152-
* Returns the page size within a buffer.
153-
*
154-
* Notes:
155-
* Assumes buffer is valid.
156-
*
157-
* The buffer can be a raw disk block and need not contain a valid
158-
* (formatted) disk page.
159-
*/
160-
/* XXX should dig out of buffer descriptor */
161-
static inline Size
162-
BufferGetPageSize(Buffer buffer)
163-
{
164-
AssertMacro(BufferIsValid(buffer));
165-
return (Size) BLCKSZ;
166-
}
167-
168-
/*
169-
* BufferGetPage
170-
* Returns the page associated with a buffer.
171-
*
172-
* When this is called as part of a scan, there may be a need for a nearby
173-
* call to TestForOldSnapshot(). See the definition of that for details.
174-
*/
175-
static inline Page
176-
BufferGetPage(Buffer buffer)
177-
{
178-
return (Page) BufferGetBlock(buffer);
179-
}
180100

181101
/*
182102
* prototypes for functions in bufmgr.c
@@ -211,12 +131,6 @@ extern void CheckPointBuffers(int flags);
211131
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
212132
extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
213133
ForkNumber forkNum);
214-
static inline BlockNumber
215-
RelationGetNumberOfBlocks(Relation reln)
216-
{
217-
return RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM);
218-
}
219-
220134
extern void FlushOneBuffer(Buffer buffer);
221135
extern void FlushRelationBuffers(Relation rel);
222136
extern void FlushRelationsAllBuffers(struct SMgrRelationData **smgrs, int nrels);
@@ -231,6 +145,9 @@ extern void DropRelationsAllBuffers(struct SMgrRelationData **smgr_reln,
231145
int nlocators);
232146
extern void DropDatabaseBuffers(Oid dbid);
233147

148+
#define RelationGetNumberOfBlocks(reln) \
149+
RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
150+
234151
extern bool BufferIsPermanent(Buffer buffer);
235152
extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
236153

@@ -276,6 +193,83 @@ extern void FreeAccessStrategy(BufferAccessStrategy strategy);
276193

277194
#ifndef FRONTEND
278195

196+
/*
197+
* BufferIsValid
198+
* True iff the given buffer number is valid (either as a shared
199+
* or local buffer).
200+
*
201+
* Note: For a long time this was defined the same as BufferIsPinned,
202+
* that is it would say False if you didn't hold a pin on the buffer.
203+
* I believe this was bogus and served only to mask logic errors.
204+
* Code should always know whether it has a buffer reference,
205+
* independently of the pin state.
206+
*
207+
* Note: For a further long time this was not quite the inverse of the
208+
* BufferIsInvalid() macro, in that it also did sanity checks to verify
209+
* that the buffer number was in range. Most likely, this macro was
210+
* originally intended only to be used in assertions, but its use has
211+
* since expanded quite a bit, and the overhead of making those checks
212+
* even in non-assert-enabled builds can be significant. Thus, we've
213+
* now demoted the range checks to assertions within the macro itself.
214+
*/
215+
static inline bool
216+
BufferIsValid(Buffer bufnum)
217+
{
218+
Assert(bufnum <= NBuffers);
219+
Assert(bufnum >= -NLocBuffer);
220+
221+
return bufnum != InvalidBuffer;
222+
}
223+
224+
/*
225+
* BufferGetBlock
226+
* Returns a reference to a disk page image associated with a buffer.
227+
*
228+
* Note:
229+
* Assumes buffer is valid.
230+
*/
231+
static inline Block
232+
BufferGetBlock(Buffer buffer)
233+
{
234+
Assert(BufferIsValid(buffer));
235+
236+
if (BufferIsLocal(buffer))
237+
return LocalBufferBlockPointers[-buffer - 1];
238+
else
239+
return (Block) (BufferBlocks + ((Size) (buffer - 1)) * BLCKSZ);
240+
}
241+
242+
/*
243+
* BufferGetPageSize
244+
* Returns the page size within a buffer.
245+
*
246+
* Notes:
247+
* Assumes buffer is valid.
248+
*
249+
* The buffer can be a raw disk block and need not contain a valid
250+
* (formatted) disk page.
251+
*/
252+
/* XXX should dig out of buffer descriptor */
253+
static inline Size
254+
BufferGetPageSize(Buffer buffer)
255+
{
256+
AssertMacro(BufferIsValid(buffer));
257+
return (Size) BLCKSZ;
258+
}
259+
260+
/*
261+
* BufferGetPage
262+
* Returns the page associated with a buffer.
263+
*
264+
* When this is called as part of a scan, there may be a need for a nearby
265+
* call to TestForOldSnapshot(). See the definition of that for details.
266+
*/
267+
static inline Page
268+
BufferGetPage(Buffer buffer)
269+
{
270+
return (Page) BufferGetBlock(buffer);
271+
}
272+
279273
/*
280274
* Check whether the given snapshot is too old to have safely read the given
281275
* page from the given table. If so, throw a "snapshot too old" error.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy