Module: xenomai-3
Branch: master
Commit: d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun Apr  2 12:29:30 2017 +0200

lib/cobalt, utils: stdio: fix wrapping of inlined fputc, putchar

Depending on the uClibc-specific, internal __STDIO_PUTC_MACRO for
detecting macro-ized *putc* services is non-portable, unlikely to work
with MUSL libc or any other libc variants.

Use a more robust approach by directly detecting the definition of
macros for those services. This change also enables non-wrapped access
to such calls, which was not available until then (__STD() calls were
routed to the wrapper regardless).

---

 configure.ac                |    7 +++++--
 include/cobalt/stdio.h      |   30 ++++++++++++++++++++----------
 lib/cobalt/printf.c         |   18 ++----------------
 lib/cobalt/wrappers.c       |    8 ++++----
 utils/slackspot/Makefile.am |    4 ++--
 utils/slackspot/slackspot.c |    1 +
 6 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/configure.ac b/configure.ac
index 26a0d5b..8222e1d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -640,7 +640,8 @@ fi
 
 dnl Internal CFLAGS and LDFLAGS, may be enhanced per-arch below
 XENO_USER_CFLAGS="$XENO_USER_APP_CFLAGS -pipe -fstrict-aliasing \
--Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long 
-Wno-unused-parameter -Werror"
+-Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-long-long \
+-Wno-unused-parameter -Werror -D__XENO__ -D__IN_XENO__"
 if test x$want_fortify = xyes -a x$debug_mode != xfull; then
    XENO_USER_CFLAGS="$XENO_USER_CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
 fi
@@ -665,7 +666,8 @@ if test x$use_assert = x; then
    XENO_USER_CFLAGS="-DNDEBUG $XENO_USER_CFLAGS"
 fi
 
-XENO_USER_CFLAGS="$XENO_USER_CFLAGS -D__XENO__ -D__IN_XENO__ 
-I$topdir/include/$rtcore_type"
+XENO_USER_CFLAGS_STDLIB="$XENO_USER_CFLAGS"
+XENO_USER_CFLAGS="$XENO_USER_CFLAGS -I$topdir/include/$rtcore_type"
 
 AC_MSG_CHECKING([whether ld supports @file])
 AC_CACHE_VAL(ac_cv_ld_file_option,
@@ -834,6 +836,7 @@ AC_SUBST(XENO_HOST_STRING)
 AC_SUBST(XENO_COBALT_CFLAGS)
 AC_SUBST(XENO_LIB_LDFLAGS)
 AC_SUBST(XENO_USER_CFLAGS)
+AC_SUBST(XENO_USER_CFLAGS_STDLIB)
 AC_SUBST(XENO_USER_LDADD)
 AC_SUBST(XENO_USER_APP_CFLAGS)
 AC_SUBST(XENO_USER_APP_LDFLAGS)
diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h
index c915e6d..7108ffb 100644
--- a/include/cobalt/stdio.h
+++ b/include/cobalt/stdio.h
@@ -63,20 +63,30 @@ COBALT_DECL(int, puts(const char *s));
 
 COBALT_DECL(int, fputs(const char *s, FILE *stream));
 
-#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
-
-COBALT_DECL(int, fputc(int c, FILE *stream));
-
+#ifndef putchar
 COBALT_DECL(int, putchar(int c));
-
 #else
-
-int __wrap_fputc(int c, FILE *stream);
-#define __real_fputc __wrap_fputc
-
+static inline int __real_putchar(int c)
+{
+       return putchar(c);
+}
 int __wrap_putchar(int c);
-#define __real_putchar __wrap_putchar
+int __cobalt_putchar(int c);
+#undef putchar
+#define putchar __wrap_putchar
+#endif
 
+#ifndef fputc
+COBALT_DECL(int, fputc(int c, FILE *stream));
+#else
+static inline int __real_fputc(int c, FILE *stream)
+{
+       return fputc(c, stream);
+}
+int __wrap_fputc(int c, FILE *stream);
+int __cobalt_fputc(int c, FILE *stream);
+#undef fputc
+#define fputc __wrap_fputc
 #endif
 
 COBALT_DECL(size_t,
diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c
index 330c964..e52a5a5 100644
--- a/lib/cobalt/printf.c
+++ b/lib/cobalt/printf.c
@@ -787,8 +787,7 @@ COBALT_IMPL(int, puts, (const char *s))
        }
 }
 
-#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
-
+#undef fputc
 COBALT_IMPL(int, fputc, (int c, FILE *stream))
 {
        if (!cobalt_is_relaxed())
@@ -799,6 +798,7 @@ COBALT_IMPL(int, fputc, (int c, FILE *stream))
        }
 }
 
+#undef putchar
 COBALT_IMPL(int, putchar, (int c))
 {
        if (!cobalt_is_relaxed())
@@ -809,20 +809,6 @@ COBALT_IMPL(int, putchar, (int c))
        }
 }
 
-#else
-
-COBALT_IMPL(int, fputc, (int c, FILE *stream))
-{
-       return fputc(c, stream);
-}
-
-COBALT_IMPL(int, putchar, (int c))
-{
-       return putchar(c);
-}
-
-#endif /* !(__UCLIBC__ && __STDIO_PUTC_MACRO) */
-
 COBALT_IMPL(size_t, fwrite, (const void *ptr, size_t size, size_t nmemb, FILE 
*stream))
 {
        if (!cobalt_is_relaxed())
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index bf1fdf4..5fa313b 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -428,21 +428,21 @@ int __real_fputs(const char *s, FILE *stream)
        return fputs(s, stream);
 }
 
-#if !defined(__UCLIBC__) || !defined(__STDIO_PUTC_MACRO)
-
+#ifndef fputc
 __weak
 int __real_fputc(int c, FILE *stream)
 {
        return fputc(c, stream);
 }
+#endif
 
+#ifndef putchar
 __weak
 int __real_putchar(int c)
 {
        return putchar(c);
 }
-
-#endif /* !(__UCLIBC__ && __STDIO_PUTC_MACRO) */
+#endif
 
 __weak
 size_t __real_fwrite(const void *ptr, size_t sz, size_t nmemb, FILE *stream)
diff --git a/utils/slackspot/Makefile.am b/utils/slackspot/Makefile.am
index 5b4e578..179243a 100644
--- a/utils/slackspot/Makefile.am
+++ b/utils/slackspot/Makefile.am
@@ -1,7 +1,7 @@
 sbin_PROGRAMS = slackspot
 
-CPPFLAGS =                                             \
-       @XENO_USER_CFLAGS@                              \
+CPPFLAGS =                             \
+       @XENO_USER_CFLAGS_STDLIB@       \
        -I$(top_srcdir)/include
 
 slackspot_SOURCES = slackspot.c
diff --git a/utils/slackspot/slackspot.c b/utils/slackspot/slackspot.c
index 4c3c4ab..88ace13 100644
--- a/utils/slackspot/slackspot.c
+++ b/utils/slackspot/slackspot.c
@@ -34,6 +34,7 @@
 #include <malloc.h>
 #include <getopt.h>
 #include <signal.h>
+#include <cobalt/uapi/signal.h>
 
 static const struct option base_options[] = {
        {


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to