fwrite: silence __wur without using inline
authorEric Blake <eblake@redhat.com>
Thu, 3 Jan 2013 16:51:44 +0000 (09:51 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 3 Jan 2013 17:05:29 +0000 (10:05 -0700)
The libvirt folks reported[1] a link error of multiple rpl_fwrite
definitions that hits only when optimization and FORTIFY_SOURCE
are both enabled, due to improper use of inline.  But since that
particular use of rpl_fwrite exists only to work around a spurious
gcc warning on some versions of glibc, we can use gcc extensions
to acheive the same effect without using inline.  This approach
copies from ignore-value.h.

[1] https://lists.gnu.org/archive/html/bug-gnulib/2013-01/msg00014.html

* lib/stdio.in.h (fwrite): Limit warn_unused_result workaround to
just gcc, and in a way that avoids inline issues.
* modules/stdio (Depends-on): Drop extern-inline.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
lib/stdio.in.h
modules/stdio

index 73c186d..0bae990 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-01-03  Eric Blake  <eblake@redhat.com>
+
+       fwrite: silence __wur without using inline
+       * lib/stdio.in.h (fwrite): Limit warn_unused_result workaround to
+       just gcc, and in a way that avoids inline issues.
+       * modules/stdio (Depends-on): Drop extern-inline.
+
 2013-01-03  Jim Meyering  <jim@meyering.net>
 
        update-copyright: avoid copyright notice date corruption
index ec39c7d..f9765d1 100644 (file)
 #ifndef _@GUARD_PREFIX@_STDIO_H
 #define _@GUARD_PREFIX@_STDIO_H
 
-_GL_INLINE_HEADER_BEGIN
-#ifndef _GL_STDIO_INLINE
-# define _GL_STDIO_INLINE _GL_INLINE
-#endif
-
 /* Get va_list.  Needed on many systems, including glibc 2.8.  */
 #include <stdarg.h>
 
@@ -583,18 +578,12 @@ _GL_CXXALIAS_SYS (fwrite, size_t,
 /* Work around glibc bug 11959
    <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>,
    which sometimes causes an unwanted diagnostic for fwrite calls.
-   This affects only function declaration attributes, so it's not
-   needed for C++.  */
-#  if !defined __cplusplus && 0 < __USE_FORTIFY_LEVEL
-_GL_STDIO_INLINE size_t _GL_ARG_NONNULL ((1, 4))
-rpl_fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
-{
-  size_t r = fwrite (ptr, s, n, stream);
-  (void) r;
-  return r;
-}
+   This affects only function declaration attributes under certain
+   versions of gcc, and is not needed for C++.  */
+#  if !defined __cplusplus && 0 < __USE_FORTIFY_LEVEL \
+  && 3 < (__GNUC__ + (4 <= __GNUC_MINOR__))
 #   undef fwrite
-#   define fwrite rpl_fwrite
+#   define fwrite(a, b, c, d) ({size_t __r = fwrite (a, b, c, d); __r; })
 #  endif
 # endif
 _GL_CXXALIASWARN (fwrite);
@@ -1338,8 +1327,6 @@ _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - "
                       "POSIX compliance");
 #endif
 
-_GL_INLINE_HEADER_END
-
 #endif /* _@GUARD_PREFIX@_STDIO_H */
 #endif /* _@GUARD_PREFIX@_STDIO_H */
 #endif
index c33ad31..54189dc 100644 (file)
@@ -7,7 +7,6 @@ lib/stdio.in.h
 m4/stdio_h.m4
 
 Depends-on:
-extern-inline
 include_next
 snippet/arg-nonnull
 snippet/c++defs