iconv-h: Avoid #define replacements in C++ mode.
authorBruno Haible <bruno@clisp.org>
Mon, 8 Mar 2010 00:00:03 +0000 (01:00 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 8 Mar 2010 02:11:10 +0000 (03:11 +0100)
ChangeLog
lib/iconv.in.h
m4/iconv_open.m4
modules/iconv-h

index 75388bc..61862eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-03-07  Bruno Haible  <bruno@clisp.org>
 
+       iconv-h: Avoid #define replacements in C++ mode.
+       * lib/iconv.in.h: Include c++defs.h, warn-on-use.h.
+       (iconv_open, iconv, iconv_close): In C++, define a namespaced alias
+       symbol.
+       * m4/iconv_open.m4 (gl_FUNC_ICONV_OPEN): Invoke gl_REPLACE_ICONV_H
+       whenever iconv is present.
+       * modules/iconv-h (Depends-on): Add c++defs, warn-on-use.
+       (Makefile.am): Update iconv.h rule.
+
        glob: Avoid #define replacements in C++ mode.
        * lib/glob.in.h: Include c++defs.h, warn-on-use.h.
        (_gl_glob_errfunc_fn): New type.
index b75ae24..c8f516b 100644 (file)
 #ifndef _GL_ICONV_H
 #define _GL_ICONV_H
 
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
 /* The definition of _GL_ARG_NONNULL is copied here.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+/* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
 #if @REPLACE_ICONV_OPEN@
 /* An iconv_open wrapper that supports the IANA standardized encoding names
    ("ISO-8859-1" etc.) as far as possible.  */
-# define iconv_open rpl_iconv_open
-extern iconv_t iconv_open (const char *tocode, const char *fromcode)
-     _GL_ARG_NONNULL ((1, 2));
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#  define iconv_open rpl_iconv_open
+# endif
+_GL_FUNCDECL_RPL (iconv_open, iconv_t,
+                  (const char *tocode, const char *fromcode)
+                  _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (iconv_open, iconv_t,
+                  (const char *tocode, const char *fromcode));
+#else
+_GL_CXXALIAS_SYS (iconv_open, iconv_t,
+                  (const char *tocode, const char *fromcode));
 #endif
+_GL_CXXALIASWARN (iconv_open);
 
 #if @REPLACE_ICONV_UTF@
 /* Special constants for supporting UTF-{16,32}{BE,LE} encodings.
@@ -57,18 +66,36 @@ extern iconv_t iconv_open (const char *tocode, const char *fromcode)
 #endif
 
 #if @REPLACE_ICONV@
-# define iconv rpl_iconv
-extern size_t iconv (iconv_t cd,
-                     @ICONV_CONST@ char **inbuf, size_t *inbytesleft,
-                     char **outbuf, size_t *outbytesleft);
-# define iconv_close rpl_iconv_close
-extern int iconv_close (iconv_t cd);
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#  define iconv rpl_iconv
+# endif
+_GL_FUNCDECL_RPL (iconv, size_t,
+                  (iconv_t cd,
+                   @ICONV_CONST@ char **inbuf, size_t *inbytesleft,
+                   char **outbuf, size_t *outbytesleft));
+_GL_CXXALIAS_RPL (iconv, size_t,
+                  (iconv_t cd,
+                   @ICONV_CONST@ char **inbuf, size_t *inbytesleft,
+                   char **outbuf, size_t *outbytesleft));
+#else
+_GL_CXXALIAS_SYS (iconv, size_t,
+                  (iconv_t cd,
+                   @ICONV_CONST@ char **inbuf, size_t *inbytesleft,
+                   char **outbuf, size_t *outbytesleft));
 #endif
+_GL_CXXALIASWARN (iconv);
 
-
-#ifdef __cplusplus
-}
+#if @REPLACE_ICONV@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#  define iconv_close rpl_iconv_close
+# endif
+_GL_FUNCDECL_RPL (iconv_close, int, (iconv_t cd));
+_GL_CXXALIAS_RPL (iconv_close, int, (iconv_t cd));
+#else
+_GL_CXXALIAS_SYS (iconv_close, int, (iconv_t cd));
 #endif
+_GL_CXXALIASWARN (iconv_close);
+
 
 #endif /* _GL_ICONV_H */
 #endif /* _GL_ICONV_H */
index d6f44fb..60f62ca 100644 (file)
@@ -1,4 +1,4 @@
-# iconv_open.m4 serial 6
+# iconv_open.m4 serial 7
 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,6 +10,8 @@ AC_DEFUN([gl_FUNC_ICONV_OPEN],
   AC_REQUIRE([AC_CANONICAL_HOST])
   AC_REQUIRE([gl_ICONV_H_DEFAULTS])
   if test "$am_cv_func_iconv" = yes; then
+    dnl Provide the <iconv.h> override, for the sake of the C++ aliases.
+    gl_REPLACE_ICONV_H
     dnl Test whether iconv_open accepts standardized encoding names.
     dnl We know that GNU libiconv and GNU libc do.
     AC_EGREP_CPP([gnu_iconv], [
index 0a3d076..b0fd137 100644 (file)
@@ -7,7 +7,9 @@ m4/iconv_h.m4
 
 Depends-on:
 include_next
+c++defs
 arg-nonnull
+warn-on-use
 
 configure.ac:
 gl_ICONV_H
@@ -17,7 +19,7 @@ BUILT_SOURCES += $(ICONV_H)
 
 # We need the following in order to create <iconv.h> when the system
 # doesn't have one that works with the given compiler.
-iconv.h: iconv.in.h $(ARG_NONNULL_H)
+iconv.h: iconv.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f $@-t $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
          sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
@@ -27,7 +29,9 @@ iconv.h: iconv.in.h $(ARG_NONNULL_H)
              -e 's|@''REPLACE_ICONV''@|$(REPLACE_ICONV)|g' \
              -e 's|@''REPLACE_ICONV_OPEN''@|$(REPLACE_ICONV_OPEN)|g' \
              -e 's|@''REPLACE_ICONV_UTF''@|$(REPLACE_ICONV_UTF)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/iconv.in.h; \
        } > $@-t && \
        mv $@-t $@