w32: Always require libiconv.

* configure.ac (missing_iconv): Set and die if we have no libiconv.
* m4/iconv.m4: Update from libiconv 1.14.
* tools/Makefile.am (gpgtar_LDADD): Add LIBICONV.
* jnlib/utf8conv.c: Always include iconv.h
(load_libiconv): Remove this w32 only function.
(iconv_open, iconv, iconv_close): Remove W32 function pointer.
(set_native_charset): Do not call load_libiconv.
(jnlib_iconv_open, jnlib_iconv, jnlib_iconv_close): Ditto.
--

This patch removes the on-demand-loading of libiconv which we did for
13 years or so.  The rationale back then was that libiconv is too
large and often not used.  Nowadays all kind of Unix software has been
ported to Windows and many of them require libiconv.  Thus in the end
there is no saving from not requiring it.  It also remove a common
source of trouble with awrong or missing iconv.dll.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2013-08-01 19:48:00 +02:00
parent 1b89863ec1
commit aff557409c
5 changed files with 174 additions and 148 deletions

View File

@ -94,6 +94,7 @@ if test "$1" = "--build-w32"; then
--with-zlib=${w32root} \
--with-regex=${w32root} \
--with-pth-prefix=${w32root} \
--with-libiconv-prefix=${w32root} \
--with-adns=${w32root} "$@"
rc=$?
exit $rc

View File

@ -979,7 +979,11 @@ AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
#
# Checking for iconv
#
missing_iconv=no
AM_ICONV
if test "$am_cv_func_iconv" != yes; then
missing_iconv=yes
fi
#
@ -1498,6 +1502,14 @@ if test "$missing_pth" = "yes"; then
***]])
die=yes
fi
if test "$missing_iconv" = "yes"; then
AC_MSG_NOTICE([[
***
*** It is now required to build with support for iconv
*** Please install a suitable iconv implementation.
***]])
die=yes
fi
if test "$die" = "yes"; then
AC_MSG_ERROR([[

View File

@ -27,9 +27,7 @@
#include <langinfo.h>
#endif
#include <errno.h>
#ifndef HAVE_W32_SYSTEM
# include <iconv.h>
#endif
#include <iconv.h>
#include "libjnlib-config.h"
#include "stringhelp.h"
@ -45,59 +43,6 @@ static int no_translation; /* Set to true if we let simply pass through. */
static int use_iconv; /* iconv comversion fucntions required. */
/* Under W32 we dlopen the iconv dll and don't require any iconv
related headers at all. However we need to define some stuff. */
#ifdef HAVE_W32_SYSTEM
typedef void *iconv_t;
#ifndef ICONV_CONST
#define ICONV_CONST const
#endif
static iconv_t (* __stdcall iconv_open) (const char *tocode,
const char *fromcode);
static size_t (* __stdcall iconv) (iconv_t cd,
const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
static int (* __stdcall iconv_close) (iconv_t cd);
static int
load_libiconv (void)
{
static int done;
if (!done)
{
void *handle;
done = 1; /* Do it right now because we might get called recursivly
through gettext. */
handle = dlopen ("iconv.dll", RTLD_LAZY);
if (handle)
{
iconv_open = dlsym (handle, "libiconv_open");
if (iconv_open)
iconv = dlsym (handle, "libiconv");
if (iconv)
iconv_close = dlsym (handle, "libiconv_close");
}
if (!handle || !iconv_close)
{
log_info (_("error loading `%s': %s\n"),
"iconv.dll", dlerror ());
log_info (_("please see %s for more information\n"),
"http://www.gnupg.org/download/iconv.html");
iconv_open = NULL;
iconv = NULL;
iconv_close = NULL;
if (handle)
dlclose (handle);
}
}
return iconv_open? 0: -1;
}
#endif /*HAVE_W32_SYSTEM*/
/* Error handler for iconv failures. This is needed to not clutter the
output with repeated diagnostics about a missing conversion. */
static void
@ -152,13 +97,13 @@ set_native_charset (const char *newset)
{
const char *full_newset;
if (!newset)
if (!newset)
{
#ifdef HAVE_W32_SYSTEM
static char codepage[30];
unsigned int cpno;
const char *aliases;
/* We are a console program thus we need to use the
GetConsoleOutputCP function and not the the GetACP which
would give the codepage for a GUI program. Note this is not
@ -201,7 +146,7 @@ set_native_charset (const char *newset)
}
#else /*!HAVE_W32_SYSTEM*/
#ifdef HAVE_LANGINFO_CODESET
newset = nl_langinfo (CODESET);
#else /*!HAVE_LANGINFO_CODESET*/
@ -225,7 +170,7 @@ set_native_charset (const char *newset)
mod = strchr (++dot, '@');
if (!mod)
mod = dot + strlen (dot);
if (mod - dot < sizeof codepage && dot != mod)
if (mod - dot < sizeof codepage && dot != mod)
{
memcpy (codepage, dot, mod - dot);
codepage [mod - dot] = 0;
@ -272,21 +217,16 @@ set_native_charset (const char *newset)
else
{
iconv_t cd;
#ifdef HAVE_W32_SYSTEM
if (load_libiconv ())
return -1;
#endif /*HAVE_W32_SYSTEM*/
cd = iconv_open (full_newset, "utf-8");
if (cd == (iconv_t)-1)
if (cd == (iconv_t)-1)
{
handle_iconv_error (full_newset, "utf-8", 0);
return -1;
}
iconv_close (cd);
cd = iconv_open ("utf-8", full_newset);
if (cd == (iconv_t)-1)
if (cd == (iconv_t)-1)
{
handle_iconv_error ("utf-8", full_newset, 0);
return -1;
@ -306,7 +246,7 @@ get_native_charset ()
}
/* Return true if the native charset is utf-8. */
int
int
is_native_utf8 (void)
{
return no_translation;
@ -353,13 +293,13 @@ native_to_utf8 (const char *orig_string)
*p = 0;
}
else
{
{
/* Need to use iconv. */
iconv_t cd;
const char *inptr;
char *outptr;
size_t inbytes, outbytes;
cd = iconv_open ("utf-8", active_charset_name);
if (cd == (iconv_t)-1)
{
@ -367,14 +307,14 @@ native_to_utf8 (const char *orig_string)
return native_to_utf8 (string);
}
for (s=string; *s; s++ )
for (s=string; *s; s++ )
{
length++;
if ((*s & 0x80))
length += 5; /* We may need up to 6 bytes for the utf8 output. */
}
buffer = jnlib_xmalloc (length + 1);
inptr = string;
inbytes = strlen (string);
outptr = buffer;
@ -448,10 +388,10 @@ do_utf8_to_native (const char *string, size_t length, int delim,
if (!nleft)
{
if (!(*s & 0x80))
{
{
/* Plain ascii. */
if ( delim != -1
&& (*s < 0x20 || *s == 0x7f || *s == delim
&& (*s < 0x20 || *s == 0x7f || *s == delim
|| (delim && *s == '\\')))
{
n++;
@ -490,35 +430,35 @@ do_utf8_to_native (const char *string, size_t length, int delim,
encbuf[encidx++] = *s;
}
else if ((*s & 0xf0) == 0xe0) /* 1110 xxxx */
{
{
val = *s & 0x0f;
nleft = 2;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xf8) == 0xf0) /* 1111 0xxx */
{
{
val = *s & 0x07;
nleft = 3;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xfc) == 0xf8) /* 1111 10xx */
{
{
val = *s & 0x03;
nleft = 4;
encidx = 0;
encbuf[encidx++] = *s;
}
else if ((*s & 0xfe) == 0xfc) /* 1111 110x */
{
{
val = *s & 0x01;
nleft = 5;
encidx = 0;
encbuf[encidx++] = *s;
}
else /* Invalid encoding: print as \xNN. */
{
{
if (p)
{
sprintf (p, "\\x%02x", *s);
@ -551,7 +491,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
val <<= 6;
val |= *s & 0x3f;
if (!--nleft) /* Ready. */
{
{
if (no_translation)
{
if (p)
@ -590,12 +530,12 @@ do_utf8_to_native (const char *string, size_t length, int delim,
if (val >= 0x80 && val < 256)
{
/* We can simply print this character */
n++;
n++;
if (p)
*p++ = val;
}
else
{
{
/* We do not have a translation: print utf8. */
if (p)
{
@ -625,7 +565,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
const char *inptr;
char *outbuf, *outptr;
size_t inbytes, outbytes;
*p = 0; /* Terminate the buffer. */
cd = iconv_open (active_charset_name, "utf-8");
@ -642,14 +582,14 @@ do_utf8_to_native (const char *string, size_t length, int delim,
inbytes = n - 1;;
inptr = buffer;
outbytes = n * MB_LEN_MAX;
if (outbytes / MB_LEN_MAX != n)
if (outbytes / MB_LEN_MAX != n)
BUG (); /* Actually an overflow. */
outbuf = outptr = jnlib_xmalloc (outbytes);
if ( iconv (cd, (ICONV_CONST char **)&inptr, &inbytes,
&outptr, &outbytes) == (size_t)-1)
&outptr, &outbytes) == (size_t)-1)
{
static int shown;
if (!shown)
log_info (_("conversion from `%s' to `%s' failed: %s\n"),
"utf-8", active_charset_name, strerror (errno));
@ -661,7 +601,7 @@ do_utf8_to_native (const char *string, size_t length, int delim,
outbuf = do_utf8_to_native (string, length, delim, 0);
}
else /* Success. */
{
{
*outptr = 0; /* Make sure it is a string. */
/* We could realloc the buffer now but I doubt that it
makes much sense given that it will get freed
@ -694,45 +634,29 @@ utf8_to_native (const char *string, size_t length, int delim)
/* Wrapper function for iconv_open, required for W32 as we dlopen that
library on that system. */
jnlib_iconv_t
/* Wrapper function for iconv_open, formerly required for W32 as we
used to dlopen that library on that system. */
jnlib_iconv_t
jnlib_iconv_open (const char *tocode, const char *fromcode)
{
#ifdef HAVE_W32_SYSTEM
if (load_libiconv ())
return (jnlib_iconv_t)(-1);
#endif /*HAVE_W32_SYSTEM*/
return (jnlib_iconv_t)iconv_open (tocode, fromcode);
}
/* Wrapper function for iconv, required for W32 as we dlopen that
library on that system. */
/* Wrapper function for iconv, formerly required for W32 as we used to
dlopen that library on that system. */
size_t
jnlib_iconv (jnlib_iconv_t cd,
const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft)
{
#ifdef HAVE_W32_SYSTEM
if (load_libiconv ())
return 0;
#endif /*HAVE_W32_SYSTEM*/
return iconv ((iconv_t)cd, (char**)inbuf, inbytesleft, outbuf, outbytesleft);
}
/* Wrapper function for iconv_close, required for W32 as we dlopen that
library on that system. */
/* Wrapper function for iconv_close, formerly required for W32 as we
used to dlopen that library on that system. */
int
jnlib_iconv_close (jnlib_iconv_t cd)
{
#ifdef HAVE_W32_SYSTEM
if (load_libiconv ())
return 0;
#endif /*HAVE_W32_SYSTEM*/
return iconv_close ((iconv_t)cd);
}

View File

@ -1,5 +1,5 @@
# iconv.m4 serial AM6 (gettext-0.17)
dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc.
# iconv.m4 serial 17 (gettext-0.18.2)
dnl Copyright (C) 2000-2002, 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@ -30,44 +30,55 @@ AC_DEFUN([AM_ICONV_LINK],
dnl Add $INCICONV to CPPFLAGS before performing the following checks,
dnl because if the user has installed libiconv and not disabled its use
dnl via --without-libiconv-prefix, he wants to use it. The first
dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
am_save_CPPFLAGS="$CPPFLAGS"
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
am_cv_func_iconv="no, consider installing GNU libiconv"
am_cv_lib_iconv=no
AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],
[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);],
am_cv_func_iconv=yes)
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdlib.h>
#include <iconv.h>
]],
[[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);]])],
[am_cv_func_iconv=yes])
if test "$am_cv_func_iconv" != yes; then
am_save_LIBS="$LIBS"
LIBS="$LIBS $LIBICONV"
AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],
[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);],
am_cv_lib_iconv=yes
am_cv_func_iconv=yes)
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdlib.h>
#include <iconv.h>
]],
[[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);]])],
[am_cv_lib_iconv=yes]
[am_cv_func_iconv=yes])
LIBS="$am_save_LIBS"
fi
])
if test "$am_cv_func_iconv" = yes; then
AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [
dnl This tests against bugs in AIX 5.1 and HP-UX 11.11.
AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
dnl Solaris 10.
am_save_LIBS="$LIBS"
if test $am_cv_lib_iconv = yes; then
LIBS="$LIBS $LIBICONV"
fi
AC_TRY_RUN([
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <iconv.h>
#include <string.h>
int main ()
{
int result = 0;
/* Test against AIX 5.1 bug: Failures are not distinguishable from successful
returns. */
{
@ -84,7 +95,47 @@ int main ()
(char **) &inptr, &inbytesleft,
&outptr, &outbytesleft);
if (res == 0)
return 1;
result |= 1;
iconv_close (cd_utf8_to_88591);
}
}
/* Test against Solaris 10 bug: Failures are not distinguishable from
successful returns. */
{
iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
if (cd_ascii_to_88591 != (iconv_t)(-1))
{
static const char input[] = "\263";
char buf[10];
const char *inptr = input;
size_t inbytesleft = strlen (input);
char *outptr = buf;
size_t outbytesleft = sizeof (buf);
size_t res = iconv (cd_ascii_to_88591,
(char **) &inptr, &inbytesleft,
&outptr, &outbytesleft);
if (res == 0)
result |= 2;
iconv_close (cd_ascii_to_88591);
}
}
/* Test against AIX 6.1..7.1 bug: Buffer overrun. */
{
iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
if (cd_88591_to_utf8 != (iconv_t)(-1))
{
static const char input[] = "\304";
static char buf[2] = { (char)0xDE, (char)0xAD };
const char *inptr = input;
size_t inbytesleft = 1;
char *outptr = buf;
size_t outbytesleft = 1;
size_t res = iconv (cd_88591_to_utf8,
(char **) &inptr, &inbytesleft,
&outptr, &outbytesleft);
if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
result |= 4;
iconv_close (cd_88591_to_utf8);
}
}
#if 0 /* This bug could be worked around by the caller. */
@ -103,7 +154,8 @@ int main ()
(char **) &inptr, &inbytesleft,
&outptr, &outbytesleft);
if ((int)res > 0)
return 1;
result |= 8;
iconv_close (cd_88591_to_utf8);
}
}
#endif
@ -117,13 +169,19 @@ int main ()
&& iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
/* Try HP-UX names. */
&& iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
return 1;
return 0;
}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
[case "$host_os" in
result |= 16;
return result;
}]])],
[am_cv_func_iconv_works=yes],
[am_cv_func_iconv_works=no],
[
changequote(,)dnl
case "$host_os" in
aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
*) am_cv_func_iconv_works="guessing yes" ;;
esac])
esac
changequote([,])dnl
])
LIBS="$am_save_LIBS"
])
case "$am_cv_func_iconv_works" in
@ -134,7 +192,7 @@ int main ()
am_func_iconv=no am_cv_lib_iconv=no
fi
if test "$am_func_iconv" = yes; then
AC_DEFINE(HAVE_ICONV, 1,
AC_DEFINE([HAVE_ICONV], [1],
[Define if you have the iconv() function and it works.])
fi
if test "$am_cv_lib_iconv" = yes; then
@ -147,17 +205,37 @@ int main ()
LIBICONV=
LTLIBICONV=
fi
AC_SUBST(LIBICONV)
AC_SUBST(LTLIBICONV)
AC_SUBST([LIBICONV])
AC_SUBST([LTLIBICONV])
])
AC_DEFUN([AM_ICONV],
dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
dnl avoid warnings like
dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
dnl This is tricky because of the way 'aclocal' is implemented:
dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
dnl Otherwise aclocal's initial scan pass would miss the macro definition.
dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
dnl warnings.
m4_define([gl_iconv_AC_DEFUN],
m4_version_prereq([2.64],
[[AC_DEFUN_ONCE(
[$1], [$2])]],
[m4_ifdef([gl_00GNULIB],
[[AC_DEFUN_ONCE(
[$1], [$2])]],
[[AC_DEFUN(
[$1], [$2])]])]))
gl_iconv_AC_DEFUN([AM_ICONV],
[
AM_ICONV_LINK
if test "$am_cv_func_iconv" = yes; then
AC_MSG_CHECKING([for iconv declaration])
AC_CACHE_VAL(am_cv_proto_iconv, [
AC_TRY_COMPILE([
AC_CACHE_VAL([am_cv_proto_iconv], [
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdlib.h>
#include <iconv.h>
extern
@ -169,12 +247,22 @@ size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, si
#else
size_t iconv();
#endif
], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
]],
[[]])],
[am_cv_proto_iconv_arg1=""],
[am_cv_proto_iconv_arg1="const"])
am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
AC_MSG_RESULT([$]{ac_t:-
}[$]am_cv_proto_iconv)
AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
AC_MSG_RESULT([
$am_cv_proto_iconv])
AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
[Define as const if the declaration of iconv() needs const.])
dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
m4_ifdef([gl_ICONV_H_DEFAULTS],
[AC_REQUIRE([gl_ICONV_H_DEFAULTS])
if test -n "$am_cv_proto_iconv_arg1"; then
ICONV_CONST="const"
fi
])
fi
])

View File

@ -118,7 +118,8 @@ gpgtar_SOURCES = \
gpgtar-list.c \
no-libgcrypt.c
gpgtar_CFLAGS = $(GPG_ERROR_CFLAGS) $(PTH_CFLAGS)
gpgtar_LDADD = $(common_libs) $(GPG_ERROR_LIBS) $(NETLIBS) $(W32SOCKLIBS)
gpgtar_LDADD = $(common_libs) $(GPG_ERROR_LIBS) \
$(NETLIBS) $(LIBICONV) $(W32SOCKLIBS)
# Make sure that all libs are build before we use them. This is
# important for things like make -j2.