]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Make redirection work better in C++ and with gcc.
authorBruno Haible <bruno@clisp.org>
Mon, 3 Jun 2002 12:28:14 +0000 (12:28 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:08:35 +0000 (12:08 +0200)
intl/ChangeLog
intl/libgnuintl.h

index 34227221eae94ff630b7b6101ba66dad4cb95549..35ff7f8a8782dfabd6ce2ad8b367dffad7cd52ec 100644 (file)
@@ -1,3 +1,10 @@
+2002-05-30  Bruno Haible  <bruno@clisp.org>
+
+       * libgnuintl.h (_INTL_REDIRECT_ASM, _INTL_REDIRECT_INLINE,
+       _INTL_REDIRECT_MACROS, _INTL_ASM, _INTL_ASMNAME, _INTL_STRINGIFY):
+       New macros. Use them instead of plain preprocessor level indirection
+       when appropriate.
+
 2002-05-28  Bruno Haible  <bruno@clisp.org>
 
        * localename.c (LANG_SORBIAN): Provide a default value, for mingw32.
index ad2aebc5bae47e0aa0f4eafab620928e989c86e6..bbb336106e557adf6c6bb133acbf089df1773ed9 100644 (file)
@@ -77,71 +77,211 @@ extern "C" {
      * libintl.so is a dependency of a dlopen()ed shared library but not
        linked to the executable at link time.
    Since Solaris gettext() behaves differently than GNU gettext(), this
-   would be unacceptable.  */
+   would be unacceptable.
 
+   The redirection happens by default through macros in C, so that &gettext
+   is independent of the compilation unit, but through inline functions in
+   C++, in order not to interfere with the name mangling of class fields or
+   class methods called 'gettext'.  */
+
+/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
+   If he doesn't, we choose the method.  A third possible method is
+   _INTL_REDIRECT_ASM, supported only by GCC.  */
+#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
+# if __GNUC__ >= 2 && (defined __STDC__ || defined __cplusplus)
+#  define _INTL_REDIRECT_ASM
+# else
+#  ifdef __cplusplus
+#   define _INTL_REDIRECT_INLINE
+#  else
+#   define _INTL_REDIRECT_MACROS
+#  endif
+# endif
+#endif
+/* Auxiliary macros.  */
+#ifdef _INTL_REDIRECT_ASM
+# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
+# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
+# define _INTL_STRINGIFY(prefix) #prefix
+#else
+# define _INTL_ASM(cname)
+#endif
 
 /* Look up MSGID in the current default message catalog for the current
    LC_MESSAGES locale.  If not found, returns MSGID itself (the default
    text).  */
-#define gettext libintl_gettext
-extern char *gettext _INTL_PARAMS ((const char *__msgid));
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_gettext (const char *__msgid);
+static inline char *gettext (const char *__msgid)
+{
+  return libintl_gettext (__msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define gettext libintl_gettext
+#endif
+extern char *gettext _INTL_PARAMS ((const char *__msgid))
+       _INTL_ASM (libintl_gettext);
+#endif
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current
    LC_MESSAGES locale.  */
-#define dgettext libintl_dgettext
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dgettext (const char *__domainname, const char *__msgid);
+static inline char *dgettext (const char *__domainname, const char *__msgid)
+{
+  return libintl_dgettext (__domainname, __msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dgettext libintl_dgettext
+#endif
 extern char *dgettext _INTL_PARAMS ((const char *__domainname,
-                                    const char *__msgid));
+                                    const char *__msgid))
+       _INTL_ASM (libintl_dgettext);
+#endif
 
 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
    locale.  */
-#define dcgettext libintl_dcgettext
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
+                               int __category);
+static inline char *dcgettext (const char *__domainname, const char *__msgid,
+                              int __category)
+{
+  return libintl_dcgettext (__domainname, __msgid, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcgettext libintl_dcgettext
+#endif
 extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
                                      const char *__msgid,
-                                     int __category));
+                                     int __category))
+       _INTL_ASM (libintl_dcgettext);
+#endif
 
 
 /* Similar to `gettext' but select the plural form corresponding to the
    number N.  */
-#define ngettext libintl_ngettext
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
+                              unsigned long int __n);
+static inline char *ngettext (const char *__msgid1, const char *__msgid2,
+                             unsigned long int __n)
+{
+  return libintl_ngettext (__msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define ngettext libintl_ngettext
+#endif
 extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
                                     const char *__msgid2,
-                                    unsigned long int __n));
+                                    unsigned long int __n))
+       _INTL_ASM (libintl_ngettext);
+#endif
 
 /* Similar to `dgettext' but select the plural form corresponding to the
    number N.  */
-#define dngettext libintl_dngettext
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
+                               const char *__msgid2, unsigned long int __n);
+static inline char *dngettext (const char *__domainname, const char *__msgid1,
+                              const char *__msgid2, unsigned long int __n)
+{
+  return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dngettext libintl_dngettext
+#endif
 extern char *dngettext _INTL_PARAMS ((const char *__domainname,
                                      const char *__msgid1,
                                      const char *__msgid2,
-                                     unsigned long int __n));
+                                     unsigned long int __n))
+       _INTL_ASM (libintl_dngettext);
+#endif
 
 /* Similar to `dcgettext' but select the plural form corresponding to the
    number N.  */
-#define dcngettext libintl_dcngettext
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcngettext (const char *__domainname,
+                                const char *__msgid1, const char *__msgid2,
+                                unsigned long int __n, int __category);
+static inline char *dcngettext (const char *__domainname,
+                               const char *__msgid1, const char *__msgid2,
+                               unsigned long int __n, int __category)
+{
+  return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcngettext libintl_dcngettext
+#endif
 extern char *dcngettext _INTL_PARAMS ((const char *__domainname,
                                       const char *__msgid1,
                                       const char *__msgid2,
                                       unsigned long int __n,
-                                      int __category));
+                                      int __category))
+       _INTL_ASM (libintl_dcngettext);
+#endif
 
 
 /* Set the current default message catalog to DOMAINNAME.
    If DOMAINNAME is null, return the current default.
    If DOMAINNAME is "", reset to the default of "messages".  */
-#define textdomain libintl_textdomain
-extern char *textdomain _INTL_PARAMS ((const char *__domainname));
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_textdomain (const char *__domainname);
+static inline char *textdomain (const char *__domainname)
+{
+  return libintl_textdomain (__domainname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define textdomain libintl_textdomain
+#endif
+extern char *textdomain _INTL_PARAMS ((const char *__domainname))
+       _INTL_ASM (libintl_textdomain);
+#endif
 
 /* Specify that the DOMAINNAME message catalog will be found
    in DIRNAME rather than in the system locale data base.  */
-#define bindtextdomain libintl_bindtextdomain
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bindtextdomain (const char *__domainname,
+                                    const char *__dirname);
+static inline char *bindtextdomain (const char *__domainname,
+                                   const char *__dirname)
+{
+  return libintl_bindtextdomain (__domainname, __dirname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bindtextdomain libintl_bindtextdomain
+#endif
 extern char *bindtextdomain _INTL_PARAMS ((const char *__domainname,
-                                          const char *__dirname));
+                                          const char *__dirname))
+       _INTL_ASM (libintl_bindtextdomain);
+#endif
 
 /* Specify the character encoding in which the messages from the
    DOMAINNAME message catalog will be returned.  */
-#define bind_textdomain_codeset libintl_bind_textdomain_codeset
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bind_textdomain_codeset (const char *__domainname,
+                                             const char *__codeset);
+static inline char *bind_textdomain_codeset (const char *__domainname,
+                                            const char *__codeset)
+{
+  return libintl_bind_textdomain_codeset (__domainname, __codeset);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bind_textdomain_codeset libintl_bind_textdomain_codeset
+#endif
 extern char *bind_textdomain_codeset _INTL_PARAMS ((const char *__domainname,
-                                                   const char *__codeset));
+                                                   const char *__codeset))
+       _INTL_ASM (libintl_bind_textdomain_codeset);
+#endif
 
 
 #ifdef __cplusplus