1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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-zlib=${w32root} \
--with-regex=${w32root} \ --with-regex=${w32root} \
--with-pth-prefix=${w32root} \ --with-pth-prefix=${w32root} \
--with-libiconv-prefix=${w32root} \
--with-adns=${w32root} "$@" --with-adns=${w32root} "$@"
rc=$? rc=$?
exit $rc exit $rc

View File

@ -979,7 +979,11 @@ AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME",
# #
# Checking for iconv # Checking for iconv
# #
missing_iconv=no
AM_ICONV 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 die=yes
fi 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 if test "$die" = "yes"; then
AC_MSG_ERROR([[ AC_MSG_ERROR([[

View File

@ -27,9 +27,7 @@
#include <langinfo.h> #include <langinfo.h>
#endif #endif
#include <errno.h> #include <errno.h>
#ifndef HAVE_W32_SYSTEM #include <iconv.h>
# include <iconv.h>
#endif
#include "libjnlib-config.h" #include "libjnlib-config.h"
#include "stringhelp.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. */ 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 /* Error handler for iconv failures. This is needed to not clutter the
output with repeated diagnostics about a missing conversion. */ output with repeated diagnostics about a missing conversion. */
static void static void
@ -273,11 +218,6 @@ set_native_charset (const char *newset)
{ {
iconv_t cd; iconv_t cd;
#ifdef HAVE_W32_SYSTEM
if (load_libiconv ())
return -1;
#endif /*HAVE_W32_SYSTEM*/
cd = iconv_open (full_newset, "utf-8"); cd = iconv_open (full_newset, "utf-8");
if (cd == (iconv_t)-1) if (cd == (iconv_t)-1)
{ {
@ -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 /* Wrapper function for iconv_open, formerly required for W32 as we
library on that system. */ used to dlopen that library on that system. */
jnlib_iconv_t jnlib_iconv_t
jnlib_iconv_open (const char *tocode, const char *fromcode) 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); return (jnlib_iconv_t)iconv_open (tocode, fromcode);
} }
/* Wrapper function for iconv, required for W32 as we dlopen that /* Wrapper function for iconv, formerly required for W32 as we used to
library on that system. */ dlopen that library on that system. */
size_t size_t
jnlib_iconv (jnlib_iconv_t cd, jnlib_iconv (jnlib_iconv_t cd,
const char **inbuf, size_t *inbytesleft, const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft) 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); return iconv ((iconv_t)cd, (char**)inbuf, inbytesleft, outbuf, outbytesleft);
} }
/* Wrapper function for iconv_close, required for W32 as we dlopen that /* Wrapper function for iconv_close, formerly required for W32 as we
library on that system. */ used to dlopen that library on that system. */
int int
jnlib_iconv_close (jnlib_iconv_t cd) 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); return iconv_close ((iconv_t)cd);
} }

View File

@ -1,5 +1,5 @@
# iconv.m4 serial AM6 (gettext-0.17) # iconv.m4 serial 17 (gettext-0.18.2)
dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc. dnl Copyright (C) 2000-2002, 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved. 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 Add $INCICONV to CPPFLAGS before performing the following checks,
dnl because if the user has installed libiconv and not disabled its use 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 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" am_save_CPPFLAGS="$CPPFLAGS"
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 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_func_iconv="no, consider installing GNU libiconv"
am_cv_lib_iconv=no am_cv_lib_iconv=no
AC_TRY_LINK([#include <stdlib.h> AC_LINK_IFELSE(
#include <iconv.h>], [AC_LANG_PROGRAM(
[iconv_t cd = iconv_open("",""); [[
#include <stdlib.h>
#include <iconv.h>
]],
[[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL); iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);], iconv_close(cd);]])],
am_cv_func_iconv=yes) [am_cv_func_iconv=yes])
if test "$am_cv_func_iconv" != yes; then if test "$am_cv_func_iconv" != yes; then
am_save_LIBS="$LIBS" am_save_LIBS="$LIBS"
LIBS="$LIBS $LIBICONV" LIBS="$LIBS $LIBICONV"
AC_TRY_LINK([#include <stdlib.h> AC_LINK_IFELSE(
#include <iconv.h>], [AC_LANG_PROGRAM(
[iconv_t cd = iconv_open("",""); [[
#include <stdlib.h>
#include <iconv.h>
]],
[[iconv_t cd = iconv_open("","");
iconv(cd,NULL,NULL,NULL,NULL); iconv(cd,NULL,NULL,NULL,NULL);
iconv_close(cd);], iconv_close(cd);]])],
am_cv_lib_iconv=yes [am_cv_lib_iconv=yes]
am_cv_func_iconv=yes) [am_cv_func_iconv=yes])
LIBS="$am_save_LIBS" LIBS="$am_save_LIBS"
fi fi
]) ])
if test "$am_cv_func_iconv" = yes; then if test "$am_cv_func_iconv" = yes; then
AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [ 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. 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" am_save_LIBS="$LIBS"
if test $am_cv_lib_iconv = yes; then if test $am_cv_lib_iconv = yes; then
LIBS="$LIBS $LIBICONV" LIBS="$LIBS $LIBICONV"
fi fi
AC_TRY_RUN([ AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <iconv.h> #include <iconv.h>
#include <string.h> #include <string.h>
int main () int main ()
{ {
int result = 0;
/* Test against AIX 5.1 bug: Failures are not distinguishable from successful /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
returns. */ returns. */
{ {
@ -84,7 +95,47 @@ int main ()
(char **) &inptr, &inbytesleft, (char **) &inptr, &inbytesleft,
&outptr, &outbytesleft); &outptr, &outbytesleft);
if (res == 0) 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. */ #if 0 /* This bug could be worked around by the caller. */
@ -103,7 +154,8 @@ int main ()
(char **) &inptr, &inbytesleft, (char **) &inptr, &inbytesleft,
&outptr, &outbytesleft); &outptr, &outbytesleft);
if ((int)res > 0) if ((int)res > 0)
return 1; result |= 8;
iconv_close (cd_88591_to_utf8);
} }
} }
#endif #endif
@ -117,13 +169,19 @@ int main ()
&& iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
/* Try HP-UX names. */ /* Try HP-UX names. */
&& iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
return 1; result |= 16;
return 0; return result;
}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no], }]])],
[case "$host_os" in [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" ;; aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
*) am_cv_func_iconv_works="guessing yes" ;; *) am_cv_func_iconv_works="guessing yes" ;;
esac]) esac
changequote([,])dnl
])
LIBS="$am_save_LIBS" LIBS="$am_save_LIBS"
]) ])
case "$am_cv_func_iconv_works" in case "$am_cv_func_iconv_works" in
@ -134,7 +192,7 @@ int main ()
am_func_iconv=no am_cv_lib_iconv=no am_func_iconv=no am_cv_lib_iconv=no
fi fi
if test "$am_func_iconv" = yes; then 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.]) [Define if you have the iconv() function and it works.])
fi fi
if test "$am_cv_lib_iconv" = yes; then if test "$am_cv_lib_iconv" = yes; then
@ -147,17 +205,37 @@ int main ()
LIBICONV= LIBICONV=
LTLIBICONV= LTLIBICONV=
fi fi
AC_SUBST(LIBICONV) AC_SUBST([LIBICONV])
AC_SUBST(LTLIBICONV) 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 AM_ICONV_LINK
if test "$am_cv_func_iconv" = yes; then if test "$am_cv_func_iconv" = yes; then
AC_MSG_CHECKING([for iconv declaration]) AC_MSG_CHECKING([for iconv declaration])
AC_CACHE_VAL(am_cv_proto_iconv, [ AC_CACHE_VAL([am_cv_proto_iconv], [
AC_TRY_COMPILE([ AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[
#include <stdlib.h> #include <stdlib.h>
#include <iconv.h> #include <iconv.h>
extern extern
@ -169,12 +247,22 @@ size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, si
#else #else
size_t iconv(); size_t iconv();
#endif #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="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/( /(/'` am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
AC_MSG_RESULT([$]{ac_t:- AC_MSG_RESULT([
}[$]am_cv_proto_iconv) $am_cv_proto_iconv])
AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
[Define as const if the declaration of iconv() needs const.]) [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 fi
]) ])

View File

@ -118,7 +118,8 @@ gpgtar_SOURCES = \
gpgtar-list.c \ gpgtar-list.c \
no-libgcrypt.c no-libgcrypt.c
gpgtar_CFLAGS = $(GPG_ERROR_CFLAGS) $(PTH_CFLAGS) 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 # Make sure that all libs are build before we use them. This is
# important for things like make -j2. # important for things like make -j2.