Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3d05965

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/20181012170355.bhxi273skjt6sag4@alap3.anarazel.de
1 parent 355684e commit 3d05965

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

src/backend/access/transam/xact.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,11 @@ AtStart_Memory(void)
10181018
*/
10191019
if (TransactionAbortContext == NULL)
10201020
TransactionAbortContext =
1021-
AllocSetContextCreateExtended(TopMemoryContext,
1022-
"TransactionAbortContext",
1023-
32 * 1024,
1024-
32 * 1024,
1025-
32 * 1024);
1021+
AllocSetContextCreate(TopMemoryContext,
1022+
"TransactionAbortContext",
1023+
32 * 1024,
1024+
32 * 1024,
1025+
32 * 1024);
10261026

10271027
/*
10281028
* We shouldn't have a transaction context already.

src/backend/utils/mmgr/aset.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ 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
388390
AllocSetContextCreateExtended(MemoryContext parent,

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
@@ -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
*/
164-
#ifdef HAVE__BUILTIN_CONSTANT_P
165-
#define AllocSetContextCreate(parent, name, allocparams) \
163+
#if defined(HAVE__BUILTIN_CONSTANT_P) && defined(HAVE__VA_ARGS)
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+
AllocSetContextCreateExtended(parent, name, __VA_ARGS__))
169168
#else
170-
#define AllocSetContextCreate(parent, name, allocparams) \
171-
AllocSetContextCreateExtended(parent, name, allocparams)
169+
#define AllocSetContextCreate \
170+
AllocSetContextCreateExtended
172171
#endif
173172

174173
/* slab.c */

0 commit comments

Comments
 (0)