Re: AllocSetContextCreate changes breake extensions

Andres Freund <andres@anarazel.de>

From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org, Christoph Berg <cb@df7cb.de>
Date: 2018-10-12T17:46:24Z
Lists: pgsql-hackers
On 2018-10-12 13:20:16 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > Christoph Berg, on IRC, raised the issue that at least one extension
> > failed compiling in v11. The extension currently does:
> > https://github.com/pgq/pgq/blob/master/triggers/common.c#L225
> > 	tbl_cache_ctx = AllocSetContextCreate(TopMemoryContext,
> > 					      "pgq_triggers table info",
> > 					      ALLOCSET_SMALL_MINSIZE,
> > 					      ALLOCSET_SMALL_INITSIZE,
> >                                               ALLOCSET_SMALL_MAXSIZE);
> 
> > which makes sense, because it has to support versions below 9.6, which
> > introduced ALLOCSET_SMALL_SIZES etc.
> 
> Yeah, we discussed that at the time and thought it was acceptable
> collateral damage.  It's not like nobody ever breaks API in new major
> versions.

Sure, we do that all the time.  It just seems quite unnecessarily
painful here, especially because ALLOCSET_*_SIZES wasn't backpatched.


> > Based on a quick look, ISTM the easiest fix is to have the
> > AllocSetContextCreate accept five parameters, and move it below the
> > ALLOCSET_*_SIZES macros. That way they should be expanded before
> > AllocSetContextCreate(), and thus 5 params should be fine.
> 
> Huh?  The order in which you #define macros doesn't affect expansion.

return -ENOCOFFEE;


But can't we just do something like:

#if defined(HAVE__BUILTIN_CONSTANT_P) && defined(HAVE__VA_ARGS)
#define AllocSetContextCreate(parent, name, ...) \
	(StaticAssertExpr(__builtin_constant_p(name), \
					  "memory context names must be constant strings"), \
	 AllocSetContextCreateExtended(parent, name, __VA_ARGS__))
#else
#define AllocSetContextCreate \
	AllocSetContextCreateExtended
#endif

The set of compilers that have __builtin_constant_p and not vararg
macros got to be about empty.


Greetings,

Andres Freund


Commits

  1. Back-patch addition of the ALLOCSET_FOO_SIZES macros.

  2. Simplify use of AllocSetContextCreate() wrapper macro.

  3. Rethink MemoryContext creation to improve performance.