]> granicus.if.org Git - postgresql/commitdiff
Simplify use of AllocSetContextCreate() wrapper macro.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 12 Oct 2018 18:26:56 +0000 (14:26 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 12 Oct 2018 18:26:56 +0000 (14:26 -0400)
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

src/backend/access/transam/xact.c
src/backend/utils/mmgr/aset.c
src/backend/utils/mmgr/mcxt.c
src/include/utils/memutils.h

index 6cd00d9aaaf696637d5d60c19cb8b2f8208b2da2..8c1621d949c6fa69b942c64c633f7ed367f91e4b 100644 (file)
@@ -1000,11 +1000,11 @@ AtStart_Memory(void)
         */
        if (TransactionAbortContext == NULL)
                TransactionAbortContext =
-                       AllocSetContextCreateExtended(TopMemoryContext,
-                                                                                 "TransactionAbortContext",
-                                                                                 32 * 1024,
-                                                                                 32 * 1024,
-                                                                                 32 * 1024);
+                       AllocSetContextCreate(TopMemoryContext,
+                                                                 "TransactionAbortContext",
+                                                                 32 * 1024,
+                                                                 32 * 1024,
+                                                                 32 * 1024);
 
        /*
         * We shouldn't have a transaction context already.
index e3d2c4e2faa05168f7d75333669352ad2a994596..44cc56c762d7f61633d9257b635b34f3a2770e28 100644 (file)
@@ -371,7 +371,7 @@ AllocSetFreeIndex(Size size)
 
 
 /*
- * AllocSetContextCreateExtended
+ * AllocSetContextCreateInternal
  *             Create a new AllocSet context.
  *
  * parent: parent context, or NULL if top-level context
@@ -381,11 +381,13 @@ AllocSetFreeIndex(Size size)
  * maxBlockSize: maximum allocation block size
  *
  * Most callers should abstract the context size parameters using a macro
- * such as ALLOCSET_DEFAULT_SIZES.  (This is now *required* when going
- * through the AllocSetContextCreate macro.)
+ * such as ALLOCSET_DEFAULT_SIZES.
+ *
+ * Note: don't call this directly; go through the wrapper macro
+ * AllocSetContextCreate.
  */
 MemoryContext
-AllocSetContextCreateExtended(MemoryContext parent,
+AllocSetContextCreateInternal(MemoryContext parent,
                                                          const char *name,
                                                          Size minContextSize,
                                                          Size initBlockSize,
index ebe0342f18e396172b5e2d552c0ddfee33ed6eec..22da98c19d93297d723fa05d25ccf468f9e978b0 100644 (file)
@@ -119,11 +119,11 @@ MemoryContextInit(void)
         * This should be the last step in this function, as elog.c assumes memory
         * management works once ErrorContext is non-null.
         */
-       ErrorContext = AllocSetContextCreateExtended(TopMemoryContext,
-                                                                                                "ErrorContext",
-                                                                                                8 * 1024,
-                                                                                                8 * 1024,
-                                                                                                8 * 1024);
+       ErrorContext = AllocSetContextCreate(TopMemoryContext,
+                                                                                "ErrorContext",
+                                                                                8 * 1024,
+                                                                                8 * 1024,
+                                                                                8 * 1024);
        MemoryContextAllowInCriticalSection(ErrorContext, true);
 }
 
index bc5757681ba2e7912c9cbb4597a35f2b18f07e6d..d68010f977497fa22da8831b529b5e96ecd3214f 100644 (file)
@@ -149,7 +149,7 @@ extern void MemoryContextCreate(MemoryContext node,
  */
 
 /* aset.c */
-extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent,
+extern MemoryContext AllocSetContextCreateInternal(MemoryContext parent,
                                                          const char *name,
                                                          Size minContextSize,
                                                          Size initBlockSize,
@@ -158,17 +158,16 @@ extern MemoryContext AllocSetContextCreateExtended(MemoryContext parent,
 /*
  * This wrapper macro exists to check for non-constant strings used as context
  * names; that's no longer supported.  (Use MemoryContextSetIdentifier if you
- * want to provide a variable identifier.)  Note you must specify block sizes
- * with one of the abstraction macros below.
+ * want to provide a variable identifier.)
  */
 #ifdef HAVE__BUILTIN_CONSTANT_P
-#define AllocSetContextCreate(parent, name, allocparams) \
+#define AllocSetContextCreate(parent, name, ...) \
        (StaticAssertExpr(__builtin_constant_p(name), \
                                          "memory context names must be constant strings"), \
-        AllocSetContextCreateExtended(parent, name, allocparams))
+        AllocSetContextCreateInternal(parent, name, __VA_ARGS__))
 #else
-#define AllocSetContextCreate(parent, name, allocparams) \
-       AllocSetContextCreateExtended(parent, name, allocparams)
+#define AllocSetContextCreate \
+       AllocSetContextCreateInternal
 #endif
 
 /* slab.c */