Hi,
The attached patch is offered for the 2010-01 commitfest.
It's also available in my git repository in the "submitted" branch:
http://git.postgresql.org/gitweb?p=users/harriman/share.git;a=shortlog;h=refs/heads/submitted
In palloc.h and pg_list.h, some inline functions are defined if
allowed by the compiler. Previously the test was gcc-specific.
This patch enables inlining on more platforms, relying on the
Autoconf-generated "configure" script to determine whether
the compiler supports inline functions.
Depending on the compiler, the keyword for defining an inline
function might be spelled as inline, __inline, or __inline__,
or none of these. "configure" finds out, and except in the
first case, puts a suitable "#define inline" into pg_config.h.
This hasn't changed.
What's new is that "configure" will add "#define HAVE_INLINE 1"
into pg_config.h if it detects that the compiler accepts inline
function definitions. palloc.h and pg_list.h will condition
their inline function definitions on HAVE_INLINE instead of
the gcc-specific __GNUC__.
After applying the patch, run these commands to update
the configure script and pg_config.h.in:
autoconf; autoheader
(Does anybody still use a C compiler that doesn't support
inline functions?)
Regards,
... kurt
Remove gcc dependency in definition of "inline" functions.
In palloc.h and pg_list.h, some inline functions are defined if
allowed by the compiler. Previously the test was gcc-specific.
Now the test is platform independent, relying on the Autoconf-
generated "configure" script to determine whether the compiler
supports inline functions.
Depending on the compiler, the keyword for defining an inline
function might be spelled as inline, __inline, or __inline__,
or none of these. "configure" finds out, and except in the
first case, puts a suitable "#define inline" into pg_config.h.
This hasn't changed.
What's new is that "configure" now adds "#define HAVE_INLINE 1"
into pg_config.h upon finding that the compiler accepts inline
function definitions. palloc.h and pg_list.h now condition
their inline function definitions on HAVE_INLINE instead of
the gcc-specific __GNUC__.
---
configure.in | 4 ++++
src/backend/nodes/list.c | 10 ++++------
src/backend/utils/mmgr/mcxt.c | 9 ++++-----
src/include/nodes/pg_list.h | 4 ++--
src/include/utils/palloc.h | 8 ++++----
5 files changed, 18 insertions(+), 17 deletions(-)
--- Kurt Harriman <[email protected]> 2009-11-29 08:22:05 -0800
diff --git a/configure.in b/configure.in
index 612e843..467f40d 100644
--- a/configure.in
+++ b/configure.in
@@ -1105,6 +1105,10 @@ PGAC_STRUCT_SOCKADDR_STORAGE
PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
PGAC_STRUCT_ADDRINFO
+if test "$ac_cv_c_inline" != no; then
+ AC_DEFINE(HAVE_INLINE, 1, [Define to 1 if inline functions are allowed in C])
+fi
+
AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
[#include <sys/param.h>
#include <sys/types.h>
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index 1ba85f4..66fa3d6 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -1224,12 +1224,10 @@ list_copy_tail(List *oldlist, int nskip)
}
/*
- * When using non-GCC compilers, we can't define these as inline
- * functions in pg_list.h, so they are defined here.
- *
- * TODO: investigate supporting inlining for some non-GCC compilers.
+ * pg_list.h defines inline versions of this function if allowed by the
+ * compiler; in which case the definitions below are skipped.
*/
-#ifndef __GNUC__
+#ifndef HAVE_INLINE
ListCell *
list_head(List *l)
@@ -1248,7 +1246,7 @@ list_length(List *l)
{
return l ? l->length : 0;
}
-#endif /* ! __GNUC__ */
+#endif /* ! HAVE_INLINE */
/*
* Temporary compatibility functions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 4939046..2c5ddbb 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -628,11 +628,10 @@ repalloc(void *pointer, Size size)
* MemoryContextSwitchTo
* Returns the current context; installs the given context.
*
- * This is inlined when using GCC.
- *
- * TODO: investigate supporting inlining for some non-GCC compilers.
+ * palloc.h defines an inline version of this function if allowed by the
+ * compiler; in which case the definition below is skipped.
*/
-#ifndef __GNUC__
+#ifndef HAVE_INLINE
MemoryContext
MemoryContextSwitchTo(MemoryContext context)
@@ -645,7 +644,7 @@ MemoryContextSwitchTo(MemoryContext context)
CurrentMemoryContext = context;
return old;
}
-#endif /* ! __GNUC__ */
+#endif /* ! HAVE_INLINE */
/*
* MemoryContextStrdup
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index 04da862..4e3e08d 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -74,7 +74,7 @@ struct ListCell
* arguments. Therefore, we implement them using GCC inline functions,
* and as regular functions with non-GCC compilers.
*/
-#ifdef __GNUC__
+#ifdef HAVE_INLINE
static __inline__ ListCell *
list_head(List *l)
@@ -98,7 +98,7 @@ list_length(List *l)
extern ListCell *list_head(List *l);
extern ListCell *list_tail(List *l);
extern int list_length(List *l);
-#endif /* __GNUC__ */
+#endif /* HAVE_INLINE */
/*
* NB: There is an unfortunate legacy from a previous incarnation of
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index e504ffa..d9eac0a 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -72,11 +72,11 @@ 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 when using GCC.
+ * But we can make it an inline function if the compiler supports it.
*/
-#ifdef __GNUC__
+#ifdef HAVE_INLINE
-static __inline__ MemoryContext
+static inline MemoryContext
MemoryContextSwitchTo(MemoryContext context)
{
MemoryContext old = CurrentMemoryContext;
@@ -87,7 +87,7 @@ MemoryContextSwitchTo(MemoryContext context)
#else
extern MemoryContext MemoryContextSwitchTo(MemoryContext context);
-#endif /* __GNUC__ */
+#endif /* HAVE_INLINE */
/*
* These are like standard strdup() except the copied string is
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers