git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 2/2] i18n: avoid conflict with ngettext from libintl
Date: Wed, 9 Mar 2011 04:52:36 -0600	[thread overview]
Message-ID: <20110309105236.GC30980@elie> (raw)
In-Reply-To: <20110309103104.GA30980@elie>

Although git itself would not be using "#include <libintl.h>" anywhere
in a NO_GETTEXT build, git's gettext.h is meant to tolerate prior
declarations from libintl, to prepare for a scenario in which some
system or compat/ header decides to start including libintl.  GNU
libintl.h defines ngettext as a macro when __OPTIMIZE__ is defined, so
take care to "#undef ngettext" if it was defined for us.

To avoid having to worry about a conflicting ngettext symbol when
libintl is part of libc, also rename the no-op ngettext stub to
git_ngettext and make ngettext a macro referring to it.  This is
probably never necessary (because git's ngettext is declared "static
inline") but it buys peace of mind.

This change does not protect against conflicts due to a header
included _after_ git's i18n support (e.g., pthread.h) being the first
to pull in libintl.  We can deal with that separately if it happens.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 gettext.h |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/gettext.h b/gettext.h
index 03fb340..a473af4 100644
--- a/gettext.h
+++ b/gettext.h
@@ -13,6 +13,10 @@
 #error "namespace conflict: '_' is pre-defined?"
 #endif
 
+#ifdef ngettext
+#undef ngettext
+#endif
+
 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
 
 #ifdef GETTEXT_POISON
@@ -26,8 +30,9 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
 	return use_gettext_poison() ? " GETTEXT POISON " : msgid;
 }
 
+#define ngettext git_ngettext
 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
-const char *ngettext(const char *msgid, const char *plu, unsigned long n)
+const char *git_ngettext(const char *msgid, const char *plu, unsigned long n)
 {
 	if (use_gettext_poison())
 		return " GETTEXT POISON ";
-- 
1.7.4.1

  parent reply	other threads:[~2011-03-09 10:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-04 13:40 [BUG] git-am silently applying patches incorrectly Colin Guthrie
2011-03-04 16:17 ` Drew Northup
2011-03-04 16:41   ` Colin Guthrie
2011-03-04 17:27     ` Junio C Hamano
2011-03-04 17:49 ` Junio C Hamano
2011-03-04 18:37   ` Junio C Hamano
2011-03-04 19:05     ` Junio C Hamano
2011-03-04 19:18       ` Linus Torvalds
2011-03-04 19:31         ` Junio C Hamano
2011-03-04 20:14           ` Alexander Miseler
2011-03-04 21:33             ` Junio C Hamano
2011-03-04 22:20               ` Colin Guthrie
2011-03-04 22:34                 ` Junio C Hamano
2011-03-04 22:42                 ` Junio C Hamano
2011-03-05 11:51                   ` Colin Guthrie
2011-03-06 22:15                     ` Junio C Hamano
2011-03-06 22:40                       ` Junio C Hamano
2011-03-06 22:56                         ` Jonathan Nieder
     [not found]                           ` <AANLkTikctSrfqKCdeYUyvUmAZjr=i7kaFhPeB-LfwgUz@mail.gmail.com>
2011-03-09 10:31                             ` [RFC/PATCH 0/2] i18n: add ngettext stub Jonathan Nieder
2011-03-09 10:46                               ` [PATCH 1/2] i18n: add stub ngettext implementation Jonathan Nieder
2011-03-09 10:52                               ` Jonathan Nieder [this message]
2011-03-09 20:43                                 ` [PATCH 2/2] i18n: avoid conflict with ngettext from libintl Junio C Hamano
2011-03-09 20:51                                   ` Jonathan Nieder
2011-03-09 20:55                                     ` Junio C Hamano
2011-03-10  3:17                                       ` [PATCH v2] i18n: add stub Q_() wrapper for ngettext Jonathan Nieder
2011-03-10  7:59                                         ` Junio C Hamano
2011-03-10  9:24                                           ` Ævar Arnfjörð Bjarmason
2011-03-10  9:21                                     ` [PATCH 2/2] i18n: avoid conflict with ngettext from libintl Ævar Arnfjörð Bjarmason
2011-03-06 22:15                     ` [BUG] git-am silently applying patches incorrectly Junio C Hamano
2011-03-07  9:37                       ` Colin Guthrie
2011-03-04 23:09               ` Alexander Miseler
2011-03-05  0:05                 ` Junio C Hamano
2011-03-04 22:58         ` Junio C Hamano
2011-03-04 21:49       ` Drew Northup

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110309105236.GC30980@elie \
    --to=jrnieder@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).