[Xenomai-git] Philippe Gerum : lib/cobalt, utils: stdio: fix wrapping of inlined fputc, putchar
Module: xenomai-3 Branch: next Commit: d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b Author: Philippe GerumDate: 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
[Xenomai-git] Philippe Gerum : lib/cobalt, utils: stdio: fix wrapping of inlined fputc, putchar
Module: xenomai-3 Branch: master Commit: d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b Author: Philippe GerumDate: 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
[Xenomai-git] Philippe Gerum : lib/cobalt, utils: stdio: fix wrapping of inlined fputc, putchar
Module: xenomai-3 Branch: stable-3.0.x Commit: d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d99e3f21e56b25a5e5cbccf3450c568cdfba6b1b Author: Philippe GerumDate: 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