Skip to content

Commit 153fb49

Browse files
avargitster
authored andcommitted
gettext: remove optional non-standard parens in N_() definition
Remove the USE_PARENS_AROUND_GETTEXT_N compile-time option which was meant to catch an inadvertent mistake which is too obscure to maintain this facility. The backstory of how USE_PARENS_AROUND_GETTEXT_N came about is: When I added the N_() macro in 6578483 (i18n: add no-op _() and N_() wrappers, 2011-02-22) it was defined as: #define N_(msgid) (msgid) This is non-standard C, as was noticed and fixed in 642f85f (i18n: avoid parenthesized string as array initializer, 2011-04-07). I.e. this needed to be defined as: #define N_(msgid) msgid Then in e62cd35 (i18n: log: mark parseopt strings for translation, 2012-08-20) when "builtin_log_usage" was marked for translation the string concatenation for passing to usage() added in 1c370ea (Show usage string for 'git log -h', 'git show -h' and 'git diff -h', 2009-08-06) was faithfully preserved: - "git log [<options>] [<since>..<until>] [[--] <path>...]\n" - " or: git show [options] <object>...", + N_("git log [<options>] [<since>..<until>] [[--] <path>...]\n") + N_(" or: git show [options] <object>..."), This was then fixed to be the expected array of usage strings in e66dc0c (log.c: fix translation markings, 2015-01-06) rather than a string with multiple "\n"-delimited usage strings, and finally in 290c8e7 (gettext.h: add parentheses around N_ expansion if supported, 2015-01-11) USE_PARENS_AROUND_GETTEXT_N was added to ensure this mistake didn't happen again. I think that even if this was a N_()-specific issue this USE_PARENS_AROUND_GETTEXT_N facility wouldn't be worth it, the issue would be too rare to worry about. But I also think that 290c8e7 which introduced USE_PARENS_AROUND_GETTEXT_N misattributed the problem. The issue wasn't with the N_() macro added in e62cd35, but that before the N_() macro existed in the codebase the initial migration to parse_options() in 1c370ea continued passsing in a "\n"-delimited string, when the new API it was migrating to supported and expected the passing of an array. Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c40894 commit 153fb49

File tree

4 files changed

+1
-49
lines changed

4 files changed

+1
-49
lines changed

Makefile

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,6 @@ all::
409409
# Define NEEDS_LIBRT if your platform requires linking with librt (glibc version
410410
# before 2.17) for clock_gettime and CLOCK_MONOTONIC.
411411
#
412-
# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
413-
# compiles the following initialization:
414-
#
415-
# static const char s[] = ("FOO");
416-
#
417-
# and define it to "no" if you need to remove the parentheses () around the
418-
# constant. The default is "auto", which means to use parentheses if your
419-
# compiler is detected to support it.
420-
#
421412
# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
422413
#
423414
# Define HAVE_GETDELIM if your system has the getdelim() function.
@@ -497,8 +488,7 @@ all::
497488
#
498489
# pedantic:
499490
#
500-
# Enable -pedantic compilation. This also disables
501-
# USE_PARENS_AROUND_GETTEXT_N to produce only relevant warnings.
491+
# Enable -pedantic compilation.
502492

503493
GIT-VERSION-FILE: FORCE
504494
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1347,14 +1337,6 @@ ifneq (,$(SOCKLEN_T))
13471337
BASIC_CFLAGS += -Dsocklen_t=$(SOCKLEN_T)
13481338
endif
13491339

1350-
ifeq (yes,$(USE_PARENS_AROUND_GETTEXT_N))
1351-
BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=1
1352-
else
1353-
ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N))
1354-
BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
1355-
endif
1356-
endif
1357-
13581340
ifeq ($(uname_S),Darwin)
13591341
ifndef NO_FINK
13601342
ifeq ($(shell test -d /sw/lib && echo y),y)

config.mak.dev

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ SPARSE_FLAGS += -Wsparse-error
44
endif
55
ifneq ($(filter pedantic,$(DEVOPTS)),)
66
DEVELOPER_CFLAGS += -pedantic
7-
# don't warn for each N_ use
8-
DEVELOPER_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
97
endif
108
DEVELOPER_CFLAGS += -Wall
119
DEVELOPER_CFLAGS += -Wdeclaration-after-statement

gettext.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,7 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
5555
}
5656

5757
/* Mark msgid for translation but do not translate it. */
58-
#if !USE_PARENS_AROUND_GETTEXT_N
5958
#define N_(msgid) msgid
60-
#else
61-
/*
62-
* Strictly speaking, this will lead to invalid C when
63-
* used this way:
64-
* static const char s[] = N_("FOO");
65-
* which will expand to
66-
* static const char s[] = ("FOO");
67-
* and in valid C, the initializer on the right hand side must
68-
* be without the parentheses. But many compilers do accept it
69-
* as a language extension and it will allow us to catch mistakes
70-
* like:
71-
* static const char *msgs[] = {
72-
* N_("one")
73-
* N_("two"),
74-
* N_("three"),
75-
* NULL
76-
* };
77-
* (notice the missing comma on one of the lines) by forcing
78-
* a compilation error, because parenthesised ("one") ("two")
79-
* will not get silently turned into ("onetwo").
80-
*/
81-
#define N_(msgid) (msgid)
82-
#endif
8359

8460
const char *get_preferred_languages(void);
8561
int is_utf8_locale(void);

git-compat-util.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,6 @@ int warn_on_fopen_errors(const char *path);
12531253
*/
12541254
int open_nofollow(const char *path, int flags);
12551255

1256-
#if !defined(USE_PARENS_AROUND_GETTEXT_N) && defined(__GNUC__)
1257-
#define USE_PARENS_AROUND_GETTEXT_N 1
1258-
#endif
1259-
12601256
#ifndef SHELL_PATH
12611257
# define SHELL_PATH "/bin/sh"
12621258
#endif

0 commit comments

Comments
 (0)