Commit 13cd7209 authored by Tom Lane's avatar Tom Lane

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
parent 24a2c436
...@@ -1000,7 +1000,7 @@ AtStart_Memory(void) ...@@ -1000,7 +1000,7 @@ AtStart_Memory(void)
*/ */
if (TransactionAbortContext == NULL) if (TransactionAbortContext == NULL)
TransactionAbortContext = TransactionAbortContext =
AllocSetContextCreateExtended(TopMemoryContext, AllocSetContextCreate(TopMemoryContext,
"TransactionAbortContext", "TransactionAbortContext",
32 * 1024, 32 * 1024,
32 * 1024, 32 * 1024,
......
...@@ -371,7 +371,7 @@ AllocSetFreeIndex(Size size) ...@@ -371,7 +371,7 @@ AllocSetFreeIndex(Size size)
/* /*
* AllocSetContextCreateExtended * AllocSetContextCreateInternal
* Create a new AllocSet context. * Create a new AllocSet context.
* *
* parent: parent context, or NULL if top-level context * parent: parent context, or NULL if top-level context
...@@ -381,11 +381,13 @@ AllocSetFreeIndex(Size size) ...@@ -381,11 +381,13 @@ AllocSetFreeIndex(Size size)
* maxBlockSize: maximum allocation block size * maxBlockSize: maximum allocation block size
* *
* Most callers should abstract the context size parameters using a macro * Most callers should abstract the context size parameters using a macro
* such as ALLOCSET_DEFAULT_SIZES. (This is now *required* when going * such as ALLOCSET_DEFAULT_SIZES.
* through the AllocSetContextCreate macro.) *
* Note: don't call this directly; go through the wrapper macro
* AllocSetContextCreate.
*/ */
MemoryContext MemoryContext
AllocSetContextCreateExtended(MemoryContext parent, AllocSetContextCreateInternal(MemoryContext parent,
const char *name, const char *name,
Size minContextSize, Size minContextSize,
Size initBlockSize, Size initBlockSize,
......
...@@ -119,7 +119,7 @@ MemoryContextInit(void) ...@@ -119,7 +119,7 @@ MemoryContextInit(void)
* This should be the last step in this function, as elog.c assumes memory * This should be the last step in this function, as elog.c assumes memory
* management works once ErrorContext is non-null. * management works once ErrorContext is non-null.
*/ */
ErrorContext = AllocSetContextCreateExtended(TopMemoryContext, ErrorContext = AllocSetContextCreate(TopMemoryContext,
"ErrorContext", "ErrorContext",
8 * 1024, 8 * 1024,
8 * 1024, 8 * 1024,
......
...@@ -149,7 +149,7 @@ extern void MemoryContextCreate(MemoryContext node, ...@@ -149,7 +149,7 @@ extern void MemoryContextCreate(MemoryContext node,
*/ */
/* aset.c */ /* aset.c */
extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent, extern MemoryContext AllocSetContextCreateInternal(MemoryContext parent,
const char *name, const char *name,
Size minContextSize, Size minContextSize,
Size initBlockSize, Size initBlockSize,
...@@ -158,17 +158,16 @@ extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent, ...@@ -158,17 +158,16 @@ extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent,
/* /*
* This wrapper macro exists to check for non-constant strings used as context * This wrapper macro exists to check for non-constant strings used as context
* names; that's no longer supported. (Use MemoryContextSetIdentifier if you * names; that's no longer supported. (Use MemoryContextSetIdentifier if you
* want to provide a variable identifier.) Note you must specify block sizes * want to provide a variable identifier.)
* with one of the abstraction macros below.
*/ */
#ifdef HAVE__BUILTIN_CONSTANT_P #ifdef HAVE__BUILTIN_CONSTANT_P
#define AllocSetContextCreate(parent, name, allocparams) \ #define AllocSetContextCreate(parent, name, ...) \
(StaticAssertExpr(__builtin_constant_p(name), \ (StaticAssertExpr(__builtin_constant_p(name), \
"memory context names must be constant strings"), \ "memory context names must be constant strings"), \
AllocSetContextCreateExtended(parent, name, allocparams)) AllocSetContextCreateInternal(parent, name, __VA_ARGS__))
#else #else
#define AllocSetContextCreate(parent, name, allocparams) \ #define AllocSetContextCreate \
AllocSetContextCreateExtended(parent, name, allocparams) AllocSetContextCreateInternal
#endif #endif
/* slab.c */ /* slab.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment