*/
#include "postgres.h"
+/* see pg_list.h */
+#define PG_LIST_INCLUDE_DEFINITIONS
+
#include "nodes/pg_list.h"
return newlist;
}
-/*
- * pg_list.h defines inline versions of these functions if allowed by the
- * compiler; in which case the definitions below are skipped.
- */
-#ifndef USE_INLINE
-
-ListCell *
-list_head(const List *l)
-{
- return l ? l->head : NULL;
-}
-
-ListCell *
-list_tail(List *l)
-{
- return l ? l->tail : NULL;
-}
-
-int
-list_length(const List *l)
-{
- return l ? l->length : 0;
-}
-#endif /* ! USE_INLINE */
-
/*
* Temporary compatibility functions
*
#include "postgres.h"
+/* see palloc.h */
+#define MCXT_INCLUDE_DEFINITIONS
+
#include "utils/memutils.h"
pointer, size);
}
-/*
- * MemoryContextSwitchTo
- * Returns the current context; installs the given context.
- *
- * palloc.h defines an inline version of this function if allowed by the
- * compiler; in which case the definition below is skipped.
- */
-#ifndef USE_INLINE
-
-MemoryContext
-MemoryContextSwitchTo(MemoryContext context)
-{
- MemoryContext old;
-
- AssertArg(MemoryContextIsValid(context));
-
- old = CurrentMemoryContext;
- CurrentMemoryContext = context;
- return old;
-}
-#endif /* ! USE_INLINE */
-
/*
* MemoryContextStrdup
* Like strdup(), but allocate from the specified context
#include "postgres.h"
+/* See sortsupport.h */
+#define SORTSUPPORT_INCLUDE_DEFINITIONS
+
#include "fmgr.h"
#include "utils/lsyscache.h"
#include "utils/sortsupport.h"
} SortShimExtra;
-/*
- * sortsupport.h defines inline versions of these functions if allowed by the
- * compiler; in which case the definitions below are skipped.
- */
-#ifndef USE_INLINE
-
-/*
- * Apply a sort comparator function and return a 3-way comparison result.
- * This takes care of handling reverse-sort and NULLs-ordering properly.
- */
-int
-ApplySortComparator(Datum datum1, bool isNull1,
- Datum datum2, bool isNull2,
- SortSupport ssup)
-{
- int compare;
-
- if (isNull1)
- {
- if (isNull2)
- compare = 0; /* NULL "=" NULL */
- else if (ssup->ssup_nulls_first)
- compare = -1; /* NULL "<" NOT_NULL */
- else
- compare = 1; /* NULL ">" NOT_NULL */
- }
- else if (isNull2)
- {
- if (ssup->ssup_nulls_first)
- compare = 1; /* NOT_NULL ">" NULL */
- else
- compare = -1; /* NOT_NULL "<" NULL */
- }
- else
- {
- compare = (*ssup->comparator) (datum1, datum2, ssup);
- if (ssup->ssup_reverse)
- compare = -compare;
- }
-
- return compare;
-}
-#endif /* ! USE_INLINE */
-
/*
* Shim function for calling an old-style comparator
*
#endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
+/*
+ * Function inlining support -- Allow modules to define functions that may be
+ * inlined, if the compiler supports it.
+ *
+ * The function bodies must be defined in the module header prefixed by
+ * STATIC_IF_INLINE, protected by a cpp symbol that the module's .c file must
+ * define. If the compiler doesn't support inline functions, the function
+ * definitions are pulled in by the .c file as regular (not inline) symbols.
+ *
+ * The header must also declare the functions' prototypes, protected by
+ * !USE_INLINE.
+ */
+#ifdef USE_INLINE
+#define STATIC_IF_INLINE static inline
+#else
+#define STATIC_IF_INLINE
+#endif /* USE_INLINE */
+
/* ----------------------------------------------------------------
* Section 7: random stuff
* ----------------------------------------------------------------
* them as macros, since we want to avoid double-evaluation of macro
* arguments. Therefore, we implement them using static inline functions
* if supported by the compiler, or as regular functions otherwise.
+ * See STATIC_IF_INLINE in c.h.
*/
-#ifdef USE_INLINE
-
-static inline ListCell *
+#ifndef USE_INLINE
+extern ListCell *list_head(const List *l);
+extern ListCell *list_tail(List *l);
+extern int list_length(const List *l);
+#endif /* USE_INLINE */
+#if defined(USE_INLINE) || defined(PG_LIST_INCLUDE_DEFINITIONS)
+STATIC_IF_INLINE ListCell *
list_head(const List *l)
{
return l ? l->head : NULL;
}
-static inline ListCell *
+STATIC_IF_INLINE ListCell *
list_tail(List *l)
{
return l ? l->tail : NULL;
}
-static inline int
+STATIC_IF_INLINE int
list_length(const List *l)
{
return l ? l->length : 0;
}
-#else
-
-extern ListCell *list_head(const List *l);
-extern ListCell *list_tail(List *l);
-extern int list_length(const List *l);
-#endif /* USE_INLINE */
+#endif /* USE_INLINE || PG_LIST_INCLUDE_DEFINITIONS */
/*
* NB: There is an unfortunate legacy from a previous incarnation of
/*
* 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;
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
} SortSupportData;
-/* ApplySortComparator should be inlined if possible */
-#ifdef USE_INLINE
-
+/*
+ * ApplySortComparator should be inlined if possible. See STATIC_IF_INLINE
+ * in c.h.
+ */
+#ifndef USE_INLINE
+extern int ApplySortComparator(Datum datum1, bool isNull1,
+ Datum datum2, bool isNull2,
+ SortSupport ssup);
+#endif /* !USE_INLINE */
+#if defined(USE_INLINE) || defined(SORTSUPPORT_INCLUDE_DEFINITIONS)
/*
* Apply a sort comparator function and return a 3-way comparison result.
* This takes care of handling reverse-sort and NULLs-ordering properly.
*/
-static inline int
+STATIC_IF_INLINE int
ApplySortComparator(Datum datum1, bool isNull1,
Datum datum2, bool isNull2,
SortSupport ssup)
return compare;
}
-#else
-
-extern int ApplySortComparator(Datum datum1, bool isNull1,
- Datum datum2, bool isNull2,
- SortSupport ssup);
-#endif /* USE_INLINE */
+#endif /* USE_INLINE || SORTSUPPORT_INCLUDE_DEFINITIONS */
/* Other functions in utils/sort/sortsupport.c */
extern void PrepareSortSupportComparisonShim(Oid cmpFunc, SortSupport ssup);