Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13cd720

Browse files
committed
Simplify use of AllocSetContextCreate() wrapper macro.
We can allow this macro to accept either abbreviated or non-abbreviated allocation parameters by making use of __VA_ARGS__. As noted by Andres Freund, it's unlikely that any compiler would have __builtin_constant_p but not __VA_ARGS__, so this gives up little or no error checking, and it avoids a minor but annoying API break for extensions. With this change, there is no reason for anybody to call AllocSetContextCreateExtended directly, so in HEAD I renamed it to AllocSetContextCreateInternal. It's probably too late for an ABI break like that in 11, though. Discussion: https://postgr.es/m/[email protected]
1 parent 24a2c43 commit 13cd720

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/backend/access/transam/xact.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,11 @@ AtStart_Memory(void)
10001000
*/
10011001
if (TransactionAbortContext == NULL)
10021002
TransactionAbortContext =
1003-
AllocSetContextCreateExtended(TopMemoryContext,
1004-
"TransactionAbortContext",
1005-
32 * 1024,
1006-
32 * 1024,
1007-
32 * 1024);
1003+
AllocSetContextCreate(TopMemoryContext,
1004+
"TransactionAbortContext",
1005+
32 * 1024,
1006+
32 * 1024,
1007+
32 * 1024);
10081008

10091009
/*
10101010
* We shouldn't have a transaction context already.

src/backend/utils/mmgr/aset.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ AllocSetFreeIndex(Size size)
371371

372372

373373
/*
374-
* AllocSetContextCreateExtended
374+
* AllocSetContextCreateInternal
375375
* Create a new AllocSet context.
376376
*
377377
* parent: parent context, or NULL if top-level context
@@ -381,11 +381,13 @@ AllocSetFreeIndex(Size size)
381381
* maxBlockSize: maximum allocation block size
382382
*
383383
* Most callers should abstract the context size parameters using a macro
384-
* such as ALLOCSET_DEFAULT_SIZES. (This is now *required* when going
385-
* through the AllocSetContextCreate macro.)
384+
* such as ALLOCSET_DEFAULT_SIZES.
385+
*
386+
* Note: don't call this directly; go through the wrapper macro
387+
* AllocSetContextCreate.
386388
*/
387389
MemoryContext
388-
AllocSetContextCreateExtended(MemoryContext parent,
390+
AllocSetContextCreateInternal(MemoryContext parent,
389391
const char *name,
390392
Size minContextSize,
391393
Size initBlockSize,

src/backend/utils/mmgr/mcxt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ MemoryContextInit(void)
119119
* This should be the last step in this function, as elog.c assumes memory
120120
* management works once ErrorContext is non-null.
121121
*/
122-
ErrorContext = AllocSetContextCreateExtended(TopMemoryContext,
123-
"ErrorContext",
124-
8 * 1024,
125-
8 * 1024,
126-
8 * 1024);
122+
ErrorContext = AllocSetContextCreate(TopMemoryContext,
123+
"ErrorContext",
124+
8 * 1024,
125+
8 * 1024,
126+
8 * 1024);
127127
MemoryContextAllowInCriticalSection(ErrorContext, true);
128128
}
129129

src/include/utils/memutils.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ extern void MemoryContextCreate(MemoryContext node,
149149
*/
150150

151151
/* aset.c */
152-
extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent,
152+
extern MemoryContext AllocSetContextCreateInternal(MemoryContext parent,
153153
const char *name,
154154
Size minContextSize,
155155
Size initBlockSize,
@@ -158,17 +158,16 @@ extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent,
158158
/*
159159
* This wrapper macro exists to check for non-constant strings used as context
160160
* names; that's no longer supported. (Use MemoryContextSetIdentifier if you
161-
* want to provide a variable identifier.) Note you must specify block sizes
162-
* with one of the abstraction macros below.
161+
* want to provide a variable identifier.)
163162
*/
164163
#ifdef HAVE__BUILTIN_CONSTANT_P
165-
#define AllocSetContextCreate(parent, name, allocparams) \
164+
#define AllocSetContextCreate(parent, name, ...) \
166165
(StaticAssertExpr(__builtin_constant_p(name), \
167166
"memory context names must be constant strings"), \
168-
AllocSetContextCreateExtended(parent, name, allocparams))
167+
AllocSetContextCreateInternal(parent, name, __VA_ARGS__))
169168
#else
170-
#define AllocSetContextCreate(parent, name, allocparams) \
171-
AllocSetContextCreateExtended(parent, name, allocparams)
169+
#define AllocSetContextCreate \
170+
AllocSetContextCreateInternal
172171
#endif
173172

174173
/* slab.c */

0 commit comments

Comments
 (0)