[klibc] ISO C99 inline, again

Thorsten Glaser tg at mirbsd.de
Sun Aug 29 08:11:17 PDT 2010


I just saw this wasn’t merged for 1.5.20 (at least the stdio.h
part, which I submitted somewhere earlier).

I did a grep for "extern.*inline" and touched all functions,
but this should be tested first (the klibc/compiler.h and
ctype.h ones, at least), as I was not 100% clear on which
behaviour exactly was *intended* in the first place.

The general idea is:
if __GNUC_STDC_INLINE__ use “static inline” else “extern inline”,
and add __attribute__((__always_inline__)) if the compiler is new
enough – which means to inline and not add a function version of
the code.

I believe no one can invent an algorithm. One just happens to hit upon it
when God enlightens him. Or only God invents algorithms, we merely copy them.
If you don't believe in God, just consider God as Nature if you won't deny
existence.		-- Coywolf Qi Hunt
-------------- next part --------------
From 5588421cf0bfd636bf5c22386e14842fa35cfa7c Mon Sep 17 00:00:00 2001
From: Thorsten Glaser <tg at mirbsd.org>
Date: Sun, 29 Aug 2010 15:06:14 +0000
Subject: [PATCH] Fix ISO C99 inline
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

• stdio.h: match style of the rest of the file and always use
  the ISO C99 “static inline” (tested)
• klibc/compiler.h: use “static inline” instead of forcing the
  GNU89 style “extern inline” (untested)
• ctype.h: match style of the rest of the file and always use
  __must_inline instead of the GNU89 style (untested)

Signed-off-by: Thorsten Glaser <tg at mirbsd.org>
 usr/include/ctype.h          |    2 +-
 usr/include/klibc/compiler.h |    3 +--
 usr/include/stdio.h          |    4 ++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/usr/include/ctype.h b/usr/include/ctype.h
index dfe1c46..00be258 100644
--- a/usr/include/ctype.h
+++ b/usr/include/ctype.h
@@ -133,7 +133,7 @@ __must_inline int __ctype_tolower(int __c)
   __extern int X(int);
 #define __CTYPEFUNC(X) \
-  __extern inline int X(int __c)		\
+  __must_inline int X(int __c)			\
   {						\
     return __ctype_##X(__c); 			\
diff --git a/usr/include/klibc/compiler.h b/usr/include/klibc/compiler.h
index 9dee742..67778c1 100644
--- a/usr/include/klibc/compiler.h
+++ b/usr/include/klibc/compiler.h
@@ -25,8 +25,7 @@
 #ifdef __GNUC__
 # if __GNUC__ >= 3
 #  ifdef __GNUC_STDC_INLINE__
-#   define __must_inline extern __inline__ \
-	__attribute__((__gnu_inline__,__always_inline__))
+#   define __must_inline static __inline__ __attribute__((__always_inline__))
 #  else
 #   define __must_inline extern __inline__ __attribute__((__always_inline__))
 #  endif
diff --git a/usr/include/stdio.h b/usr/include/stdio.h
index 7d2c86d..14f85b2 100644
--- a/usr/include/stdio.h
+++ b/usr/include/stdio.h
@@ -85,12 +85,12 @@ __extern size_t _fread(void *, size_t, FILE *);
 __extern size_t _fwrite(const void *, size_t, FILE *);
-extern __inline__ size_t fread(void *__p, size_t __s, size_t __n, FILE * __f)
+static __inline__ size_t fread(void *__p, size_t __s, size_t __n, FILE * __f)
 	return _fread(__p, __s * __n, __f) / __s;
-extern __inline__ size_t
+static __inline__ size_t
 fwrite(const void *__p, size_t __s, size_t __n, FILE * __f)
 	return _fwrite(__p, __s * __n, __f) / __s;

More information about the klibc mailing list