[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] stdlib: support non-GCC __attribute__
From: |
Bruno Haible |
Subject: |
Re: [PATCH] stdlib: support non-GCC __attribute__ |
Date: |
Sun, 13 Feb 2011 12:43:13 +0100 |
User-agent: |
KMail/1.9.9 |
Paul Eggert wrote:
> If this seems OK, we can install similar workarounds for other
> misuses of __attribute__ in Gnulib now.
Yes, I agree gnulib should not interfere with the definition of
__attribute__ that the application has provided in its .h files.
Here's a proposed patch. I think the definitions of __attributes__ in
.c files have a low risk and can be left alone.
2011-02-13 Bruno Haible <address@hidden>
Don't interfere with a program's definition of __attribute__.
* lib/argp.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(argp_error, __argp_error, argp_failure, __argp_failure): Use it.
* lib/argp-fmtstream.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(__argp_fmtstream_printf, argp_fmtstream_printf): Use it.
* lib/argp-help.c (hol_entry_long_iterate): Use __attribute__ only for
GCC 3 or newer.
* lib/error.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(error, error_at_line): Use it.
* lib/hash.h (__attribute__): Remove definition.
(ATTRIBUTE_WUR): Update definition.
* lib/openat.h (__attribute__): Remove definition.
(ATTRIBUTE_NORETURN): Update definition.
* lib/sigpipe-die.h (__attribute__): Remove definition.
(ATTRIBUTE_NORETURN): Update definition.
* lib/vasnprintf.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(asnprintf, vasnprintf): Use it.
* lib/xalloc.h (__attribute__): Remove definition.
(ATTRIBUTE_NORETURN): Update definition.
* lib/xmemdup0.h (__attribute__): Remove definition.
(ATTRIBUTE_NORETURN): Update definition.
* lib/xprintf.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(xprintf, xvprintf, xfprintf, xvfprintf): Use it.
* lib/xstrtol.h (__attribute__): Remove definition.
(ATTRIBUTE_NORETURN): Update definition.
* lib/xvasprintf.h (__attribute__): Remove definition.
(_GL_ATTRIBUTE_FORMAT): New macro.
(xasprintf, xvasprintf): Use it.
--- lib/argp-fmtstream.h.orig Sun Feb 13 12:34:37 2011
+++ lib/argp-fmtstream.h Sun Feb 13 12:24:07 2011
@@ -28,15 +28,17 @@
#include <string.h>
#include <unistd.h>
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
@@ -128,10 +130,10 @@
extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
const char *__fmt, ...)
- __attribute__ ((__format__ (printf, 2, 3)));
+ _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
const char *__fmt, ...)
- __attribute__ ((__format__ (printf, 2, 3)));
+ _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
#if _LIBC || !defined __OPTIMIZE__
extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
--- lib/argp-help.c.orig Sun Feb 13 12:34:37 2011
+++ lib/argp-help.c Sun Feb 13 12:19:32 2011
@@ -570,7 +570,9 @@
}
static inline int
+#if __GNUC__ >= 3
__attribute__ ((always_inline))
+#endif
hol_entry_long_iterate (const struct hol_entry *entry,
int (*func)(const struct argp_option *opt,
const struct argp_option *real,
--- lib/argp.h.orig Sun Feb 13 12:34:37 2011
+++ lib/argp.h Sun Feb 13 12:23:52 2011
@@ -34,15 +34,17 @@
# define __NTH(fct) fct __THROW
#endif
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
@@ -530,10 +532,10 @@
message, then exit (1). */
extern void argp_error (const struct argp_state *__restrict __state,
const char *__restrict __fmt, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
extern void __argp_error (const struct argp_state *__restrict __state,
const char *__restrict __fmt, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
/* Similar to the standard gnu error-reporting function error(), but will
respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
@@ -546,11 +548,11 @@
extern void argp_failure (const struct argp_state *__restrict __state,
int __status, int __errnum,
const char *__restrict __fmt, ...)
- __attribute__ ((__format__ (__printf__, 4, 5)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5));
extern void __argp_failure (const struct argp_state *__restrict __state,
int __status, int __errnum,
const char *__restrict __fmt, ...)
- __attribute__ ((__format__ (__printf__, 4, 5)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5));
#if _LIBC || !defined __USE_EXTERN_INLINES
/* Returns true if the option OPT is a valid short option. */
--- lib/error.h.orig Sun Feb 13 12:34:37 2011
+++ lib/error.h Sun Feb 13 12:24:19 2011
@@ -19,15 +19,17 @@
#ifndef _ERROR_H
#define _ERROR_H 1
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
@@ -40,11 +42,11 @@
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
extern void error (int __status, int __errnum, const char *__format, ...)
- __attribute__ ((__format__ (__printf__, 3, 4)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
extern void error_at_line (int __status, int __errnum, const char *__fname,
unsigned int __lineno, const char *__format, ...)
- __attribute__ ((__format__ (__printf__, 5, 6)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6));
/* If NULL, error will flush stdout, then print on stderr the program
name, a colon and a space. Otherwise, error will call this
--- lib/hash.h.orig Sun Feb 13 12:34:37 2011
+++ lib/hash.h Sun Feb 13 12:11:14 2011
@@ -27,15 +27,14 @@
# include <stdio.h>
# include <stdbool.h>
-/* The warn_unused_result attribute appeared first in gcc-3.4.0 */
-# ifndef __attribute__
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
-# define __attribute__(x)
-# endif
-# endif
-
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The warn_unused_result attribute appeared first in gcc-3.4.0. */
# ifndef ATTRIBUTE_WUR
-# define ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__))
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# define ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__))
+# else
+# define ATTRIBUTE_WUR /* empty */
+# endif
# endif
typedef size_t (*Hash_hasher) (const void *, size_t);
--- lib/openat.h.orig Sun Feb 13 12:34:37 2011
+++ lib/openat.h Sun Feb 13 12:14:10 2011
@@ -27,14 +27,12 @@
#include <unistd.h>
#include <stdbool.h>
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x) /* empty */
-# endif
-#endif
-
#ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# else
+# define ATTRIBUTE_NORETURN /* empty */
+# endif
#endif
#if !HAVE_OPENAT
--- lib/sigpipe-die.h.orig Sun Feb 13 12:34:37 2011
+++ lib/sigpipe-die.h Sun Feb 13 12:06:40 2011
@@ -47,14 +47,12 @@
#endif
-# ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x)
-# endif
-# endif
-
# ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# else
+# define ATTRIBUTE_NORETURN /* empty */
+# endif
# endif
/* Emit an error message indicating a SIGPIPE signal, and terminate the
--- lib/vasnprintf.h.orig Sun Feb 13 12:34:37 2011
+++ lib/vasnprintf.h Sun Feb 13 12:23:26 2011
@@ -24,15 +24,17 @@
/* Get size_t. */
#include <stddef.h>
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
@@ -69,9 +71,9 @@
# define vasnprintf rpl_vasnprintf
#endif
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format,
...)
- __attribute__ ((__format__ (__printf__, 3, 4)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char
*format, va_list args)
- __attribute__ ((__format__ (__printf__, 3, 0)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
#ifdef __cplusplus
}
--- lib/xalloc.h.orig Sun Feb 13 12:34:37 2011
+++ lib/xalloc.h Sun Feb 13 12:12:07 2011
@@ -26,14 +26,12 @@
# endif
-# ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x)
-# endif
-# endif
-
# ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# else
+# define ATTRIBUTE_NORETURN /* empty */
+# endif
# endif
# ifndef ATTRIBUTE_MALLOC
--- lib/xmemdup0.h.orig Sun Feb 13 12:34:37 2011
+++ lib/xmemdup0.h Sun Feb 13 12:09:26 2011
@@ -25,14 +25,12 @@
extern "C" {
# endif
-# ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x)
-# endif
-# endif
-
# ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# else
+# define ATTRIBUTE_NORETURN /* empty */
+# endif
# endif
/* This function is always triggered when memory is exhausted.
--- lib/xprintf.h.orig Sun Feb 13 12:34:37 2011
+++ lib/xprintf.h Sun Feb 13 12:23:04 2011
@@ -20,26 +20,28 @@
#include <stdarg.h>
#include <stdio.h>
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
extern int xprintf (char const *restrict format, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
extern int xvprintf (char const *restrict format, va_list args)
- __attribute__ ((__format__ (__printf__, 1, 0)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
extern int xfprintf (FILE *restrict stream, char const *restrict format, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
extern int xvfprintf (FILE *restrict stream, char const *restrict format,
va_list args)
- __attribute__ ((__format__ (__printf__, 2, 0)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0));
#endif
--- lib/xstrtol.h.orig Sun Feb 13 12:34:37 2011
+++ lib/xstrtol.h Sun Feb 13 12:07:17 2011
@@ -51,14 +51,12 @@
_DECLARE_XSTRTOL (xstrtoull, unsigned long long int)
#endif
-#ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x)
-# endif
-#endif
-
#ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# else
+# define ATTRIBUTE_NORETURN /* empty */
+# endif
#endif
/* Report an error for an invalid integer in an option argument.
--- lib/xvasprintf.h.orig Sun Feb 13 12:34:37 2011
+++ lib/xvasprintf.h Sun Feb 13 12:24:31 2011
@@ -20,15 +20,17 @@
/* Get va_list. */
#include <stdarg.h>
-#ifndef __attribute__
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable __attribute__ only if these are supported too, because
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(Spec) /* empty */
+#ifndef _GL_ATTRIBUTE_FORMAT
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+# else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
# endif
#endif
@@ -44,9 +46,9 @@
- [EILSEQ] error during conversion between wide and multibyte characters,
return NULL. */
extern char *xasprintf (const char *format, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
extern char *xvasprintf (const char *format, va_list args)
- __attribute__ ((__format__ (__printf__, 1, 0)));
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
#ifdef __cplusplus
}
--
In memoriam Alexander Samoylovich
<http://en.wikipedia.org/wiki/Alexander_Samoylovich>
- [PATCH] stdlib: support non-GCC __attribute__, Paul Eggert, 2011/02/12
- Re: [PATCH] stdlib: support non-GCC __attribute__,
Bruno Haible <=
- Re: [PATCH] stdlib: support non-GCC __attribute__, Paul Eggert, 2011/02/13
- Re: [PATCH] stdlib: support non-GCC __attribute__, Bruno Haible, 2011/02/13
- Re: [PATCH] stdlib: support non-GCC __attribute__, Jim Meyering, 2011/02/14
- Re: [PATCH] stdlib: support non-GCC __attribute__, Paul Eggert, 2011/02/14
- Re: [PATCH] stdlib: support non-GCC __attribute__, Bruno Haible, 2011/02/14
- Re: installable stdlib.h, Bruno Haible, 2011/02/13
- Re: installable stdlib.h, Paul Eggert, 2011/02/13