This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

format_arg attributes in glibc


glibc currently uses some format_arg function attributes unconditionally
in libintl.h.  It seems that this was added during gcc 2.8 development;
since some people will probably still be compiling programs against glibc
2.2 with gcc 2.7, this should be appropriately conditioned.

At present gcc internally adds the format_arg attributes for certain
functions, but I think that this is inappropriate for strict standards
modes (-ansi, -std=c89, -std=c99), just as these modes turn on
-fno-nonansi-builtin.  Accordingly I think glibc should allow for possible
future change and state the attributes explicitly for those functions as
well.

This patch adds a conditional definition of __attribute_format_arg__ to
<sys/cdefs.h>, and adjusts libintl.h to use it, for the functions where
gcc currently adds the attribute itself, for the __-prefixed versions of
those functions, and for those places where the format_arg attribute is
presently used unconditionally.

--- misc/sys/cdefs.h.orig	Sat Jul  1 11:03:15 2000
+++ misc/sys/cdefs.h	Sun Jul 16 09:52:51 2000
@@ -141,6 +141,15 @@
 # define __attribute_pure__ /* Ignore */
 #endif
 
+/* At some point during the gcc 2.8 development the `format_arg' attribute
+   for functions was introduced.  We don't want to use it unconditionally
+   (although this would be possible) since it generates warnings.  */
+#if __GNUC_PREREQ (2,8)
+# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
+#else
+# define __attribute_format_arg__(x) /* Ignore */
+#endif
+
 /* It is possible to compile containing GCC extensions even if GCC is
    run in pedantic mode if the uses are carefully marked using the
    `__extension__' keyword.  But this is not generally available before
--- intl/libintl.h.orig	Fri May  5 11:28:57 2000
+++ intl/libintl.h	Sun Jul 16 10:01:56 2000
@@ -31,41 +31,44 @@
 /* Look up MSGID in the current default message catalog for the current
    LC_MESSAGES locale.  If not found, returns MSGID itself (the default
    text).  */
-extern char *gettext (__const char *__msgid) __THROW;
+extern char *gettext (__const char *__msgid)
+     __THROW __attribute_format_arg__ (1);
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current
    LC_MESSAGES locale.  */
-extern char *dgettext (__const char *__domainname,
-		       __const char *__msgid) __THROW;
-extern char *__dgettext (__const char *__domainname,
-			 __const char *__msgid) __THROW;
+extern char *dgettext (__const char *__domainname, __const char *__msgid)
+     __THROW __attribute_format_arg__ (2);
+extern char *__dgettext (__const char *__domainname, __const char *__msgid)
+     __THROW __attribute_format_arg__ (2);
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
    locale.  */
 extern char *dcgettext (__const char *__domainname,
-			__const char *__msgid, int __category) __THROW;
+			__const char *__msgid, int __category)
+     __THROW __attribute_format_arg__ (2);
 extern char *__dcgettext (__const char *__domainname,
-			  __const char *__msgid, int __category) __THROW;
+			  __const char *__msgid, int __category)
+     __THROW __attribute_format_arg__ (2);
 
 
 /* Similar to `gettext' but select the plural form corresponding to the
    number N.  */
 extern char *ngettext (__const char *__msgid1, __const char *__msgid2,
 		       unsigned long int __n)
-     __THROW __attribute__ ((__format_arg__ (1)));
+     __THROW __attribute_format_arg__ (1);
 
 /* Similar to `dgettext' but select the plural form corresponding to the
    number N.  */
 extern char *dngettext (__const char *__domainname, __const char *__msgid1,
 			__const char *__msgid2, unsigned long int __n)
-     __THROW __attribute__ ((__format_arg__ (2)));
+     __THROW __attribute_format_arg__ (2);
 
 /* Similar to `dcgettext' but select the plural form corresponding to the
    number N.  */
 extern char *dcngettext (__const char *__domainname, __const char *__msgid1,
 			 __const char *__msgid2, unsigned long int __n,
 			 int __category)
-     __THROW __attribute__ ((__format_arg__ (2)));
+     __THROW __attribute_format_arg__ (2);
 
 
 /* Set the current default message catalog to DOMAINNAME.


-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]