Skip to content

Commit 05f9084

Browse files
committed
Various cleanups of the new memory context header code
Robert Haas reported that his older clang compiler didn't like the two Asserts which were verifying that the given MemoryContextMethodID was <= MEMORY_CONTEXT_METHODID_MASK when building with -Wtautological-constant-out-of-range-compare. In my (David's) opinion, the compiler is wrong to warn about that. Newer versions of clang don't warn about the out of range enum value, so perhaps this was a bug that has now been fixed. To keep older clang versions happy, let's just cast the enum value to int to stop the compiler complaining. The main reason for the Asserts mentioned above to exist are to inform future developers which are adding new MemoryContexts if they run out of bit space in MemoryChunk to store the MemoryContextMethodID. As pointed out by Tom Lane, it seems wise to also add a comment to the header for that enum to document the restriction on these enum values. Additionally, also fix an incorrect usage of UINT64CONST() which was introduced in c6e0fe1. Author: Robert Haas, David Rowley Discussion: https://postgr.es/m/CA+TgmoYGG2C7Vbw1cjkQRRBL3zOk8SmhrQnsJgzscX=N9AwPrw@mail.gmail.com
1 parent 5495796 commit 05f9084

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/include/utils/memutils_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ extern void SlabCheck(MemoryContext context);
7474
* MemoryContextMethodID
7575
* A unique identifier for each MemoryContext implementation which
7676
* indicates the index into the mcxt_methods[] array. See mcxt.c.
77+
* The maximum value for this enum is constrained by
78+
* MEMORY_CONTEXT_METHODID_MASK. If an enum value higher than that is
79+
* required then MEMORY_CONTEXT_METHODID_BITS will need to be increased.
7780
*/
7881
typedef enum MemoryContextMethodID
7982
{
@@ -88,7 +91,7 @@ typedef enum MemoryContextMethodID
8891
*/
8992
#define MEMORY_CONTEXT_METHODID_BITS 3
9093
#define MEMORY_CONTEXT_METHODID_MASK \
91-
UINT64CONST((1 << MEMORY_CONTEXT_METHODID_BITS) - 1)
94+
((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1)
9295

9396
/*
9497
* This routine handles the context-type-independent part of memory

src/include/utils/memutils_memorychunk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ MemoryChunkSetHdrMask(MemoryChunk *chunk, void *block,
159159
Assert((char *) chunk > (char *) block);
160160
Assert(blockoffset <= MEMORYCHUNK_MAX_BLOCKOFFSET);
161161
Assert(value <= MEMORYCHUNK_MAX_VALUE);
162-
Assert(methodid <= MEMORY_CONTEXT_METHODID_MASK);
162+
Assert((int) methodid <= MEMORY_CONTEXT_METHODID_MASK);
163163

164164
chunk->hdrmask = (((uint64) blockoffset) << MEMORYCHUNK_BLOCKOFFSET_BASEBIT) |
165165
(((uint64) value) << MEMORYCHUNK_VALUE_BASEBIT) |
@@ -175,7 +175,7 @@ static inline void
175175
MemoryChunkSetHdrMaskExternal(MemoryChunk *chunk,
176176
MemoryContextMethodID methodid)
177177
{
178-
Assert(methodid <= MEMORY_CONTEXT_METHODID_MASK);
178+
Assert((int) methodid <= MEMORY_CONTEXT_METHODID_MASK);
179179

180180
chunk->hdrmask = MEMORYCHUNK_MAGIC | (((uint64) 1) << MEMORYCHUNK_EXTERNAL_BASEBIT) |
181181
methodid;

0 commit comments

Comments
 (0)