1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Add support for easily declaring static inline functions

We already had those, but they forced modules to spell out the function
bodies twice.  Eliminate some duplicates we had already grown.

Extracted from a somewhat larger patch from Andres Freund.
This commit is contained in:
Alvaro Herrera
2012-10-08 16:12:27 -03:00
parent 08c8058ce9
commit 976fa10d20
7 changed files with 59 additions and 117 deletions

View File

@ -73,14 +73,19 @@ extern void *repalloc(void *pointer, Size size);
/*
* MemoryContextSwitchTo can't be a macro in standard C compilers.
* But we can make it an inline function if the compiler supports it.
* See STATIC_IF_INLINE in c.h.
*
* This file has to be includable by some non-backend code such as
* pg_resetxlog, so don't expose the CurrentMemoryContext reference
* if FRONTEND is defined.
*/
#if defined(USE_INLINE) && !defined(FRONTEND)
#ifndef FRONTEND
static inline MemoryContext
#ifndef USE_INLINE
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
#endif /* !USE_INLINE */
#if defined(USE_INLINE) || defined(MCXT_INCLUDE_DEFINITIONS)
STATIC_IF_INLINE MemoryContext
MemoryContextSwitchTo(MemoryContext context)
{
MemoryContext old = CurrentMemoryContext;
@ -88,10 +93,9 @@ MemoryContextSwitchTo(MemoryContext context)
CurrentMemoryContext = context;
return old;
}
#else
#endif
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
#endif /* USE_INLINE && !FRONTEND */
#endif /* !FRONTEND */
/*
* These are like standard strdup() except the copied string is