[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Tweak NLS for better gcc printf format checking

From: Philip Martin <philip_at_codematters.co.uk>
Date: 2005-08-19 22:33:34 CEST

"Jonathan Gilbert" <o2w9gs702@sneakemail.com> writes:

> At 06:48 PM 19/08/2005 +0100, Philip Martin wrote:
>>Well, I haven't done much Subversion coding recently, but working on
>>r15828 leads me to make the following observations:
> [snip]
>>2. I18N
>>
>> Using _("foo %s bar") defeats gcc's printf format string checking,
>> if I insert '#define _(X) X' it starts working. Is there some
>> magic way to configure/build so that all the formats get checked?

I suspect --disable-nls is the required magic, at the expense of
needed a separate build to check formats.

> [snip]
>
> One approach would be to add an attribute to the declaration of '_',
> turning it into function:
>
> char *_(const char *msgid) __attribute__((__format_arg__(1),
> __always_inline__))
> {
> return libintl_gettext(msgid);
> }
>
> This tells GCC that when '_' is passed as a format parameter to a
> printf-like function, the argument to '_' should be used for type-checking
> the arguments.

Looks promising, this seems to work

Index: configure.in
===================================================================
--- configure.in (revision 15767)
+++ configure.in (working copy)
@@ -299,9 +299,17 @@
 AH_BOTTOM(
 #define N_(x) x
 #ifdef ENABLE_NLS
+#ifndef SVN_GETTEXT
+#define SVN_GETTEXT
 #include <locale.h>
 #include <libintl.h>
-#define _(x) dgettext(PACKAGE_NAME, x)
+static char *_(const char *x)
+ __attribute__((__format_arg__(1), __always_inline__, __unused__));
+static char *_(const char *x)
+{
+ return dgettext(PACKAGE_NAME, x);
+}
+#endif /* SVN_GETTEXT */
 #else
 #define _(x) (x)
 #define gettext(x) (x)

I have to use a declaration/definition pair because my gcc doesn't
support attributes on definitions. I have to use SVN_GETTEXT since
this ends up in svn_private_config.h which doesn't have include
guards (it's autoheader/autoconf generated). I have to use __unused__
because not all the files that include svn_private_config.h use _.

Compilers that don't support the gcc attributes may have problems.
__format_arg__ and __always_inline__ are probably OK, I suspect we
could drop __always_inline__ altogther. A compiler that doesn't
support __unused__ may generate "defined bu not used" warnings, that
could be a problem.

What do people think?

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Aug 19 22:37:28 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.