diff options
Diffstat (limited to 'iconv')
34 files changed, 382 insertions, 148 deletions
diff --git a/iconv/Makefile b/iconv/Makefile index b008707eb5..d71319b39e 100644 --- a/iconv/Makefile +++ b/iconv/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1997-2016 Free Software Foundation, Inc. +# Copyright (C) 1997-2018 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -31,36 +31,51 @@ routines += gconv_dl vpath %.c ../locale/programs ../intl iconv_prog-modules = iconv_charmap charmap charmap-dir linereader \ - dummy-repertoire simple-hash xstrdup xmalloc + dummy-repertoire simple-hash xstrdup xmalloc \ + record-status iconvconfig-modules = strtab xmalloc hash-string extra-objs = $(iconv_prog-modules:=.o) $(iconvconfig-modules:=.o) -CFLAGS-iconv_prog.c = -I../locale/programs -CFLAGS-iconv_charmap.c = -I../locale/programs -CFLAGS-dummy-repertoire.c = -I../locale/programs -CFLAGS-charmap.c = -DCHARMAP_PATH='"$(i18ndir)/charmaps"' \ +CFLAGS-iconv_prog.c += -I../locale/programs +CFLAGS-iconv_charmap.c += -I../locale/programs +CFLAGS-dummy-repertoire.c += -I../locale/programs +CFLAGS-charmap.c += -DCHARMAP_PATH='"$(i18ndir)/charmaps"' \ -DDEFAULT_CHARMAP=null_pointer -DNEED_NULL_POINTER -CFLAGS-linereader.c = -DNO_TRANSLITERATION -CFLAGS-simple-hash.c = -I../locale +CFLAGS-linereader.c += -DNO_TRANSLITERATION +CFLAGS-simple-hash.c += -I../locale -tests = tst-iconv1 tst-iconv2 tst-iconv3 tst-iconv4 tst-iconv5 +tests = tst-iconv1 tst-iconv2 tst-iconv3 tst-iconv4 tst-iconv5 tst-iconv6 others = iconv_prog iconvconfig install-others-programs = $(inst_bindir)/iconv install-sbin = iconvconfig CFLAGS-gconv_cache.c += -DGCONV_DIR='"$(gconvdir)"' -CFLAGS-gconv_conf.c = -DGCONV_PATH='"$(gconvdir)"' -CFLAGS-iconvconfig.c = -DGCONV_PATH='"$(gconvdir)"' -DGCONV_DIR='"$(gconvdir)"' +CFLAGS-gconv_conf.c += -DGCONV_PATH='"$(gconvdir)"' +CFLAGS-iconvconfig.c += -DGCONV_PATH='"$(gconvdir)"' -DGCONV_DIR='"$(gconvdir)"' # Set libof-* for each routine. cpp-srcs-left := $(iconv_prog-modules) $(iconvconfig-modules) lib := iconvprogs -include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left)) +include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left)) ifeq ($(run-built-tests),yes) xtests-special += $(objpfx)test-iconvconfig.out endif +# Make a copy of the file because gconv module names are constructed +# relative to the path of the configuration file. +$(objpfx)gconv-modules: test-gconv-modules + cp $< $@ + +ifeq (yes,$(build-shared)) +tests += tst-gconv-init-failure +modules-names += tst-gconv-init-failure-mod +modules-names-tests += tst-gconv-init-failure-mod +$(objpfx)tst-gconv-init-failure-mod.so: $(libsupport) +$(objpfx)tst-gconv-init-failure.out: \ + $(objpfx)gconv-modules $(objpfx)tst-gconv-init-failure-mod.so +endif + include ../Rules $(inst_bindir)/iconv: $(objpfx)iconv_prog $(+force) diff --git a/iconv/dummy-repertoire.c b/iconv/dummy-repertoire.c index 0c29c2e7f7..6309eaacb2 100644 --- a/iconv/dummy-repertoire.c +++ b/iconv/dummy-repertoire.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. +/* Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. diff --git a/iconv/gconv.c b/iconv/gconv.c index 1ffb9343e1..2612a4f52b 100644 --- a/iconv/gconv.c +++ b/iconv/gconv.c @@ -1,6 +1,6 @@ /* Convert characters in input buffer using conversion descriptor to output buffer. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -28,7 +28,6 @@ int -internal_function __gconv (__gconv_t cd, const unsigned char **inbuf, const unsigned char *inbufend, unsigned char **outbuf, unsigned char *outbufend, size_t *irreversible) diff --git a/iconv/gconv.h b/iconv/gconv.h index 8d8ce5813b..e53f4dba0e 100644 --- a/iconv/gconv.h +++ b/iconv/gconv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. +/* Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -23,9 +23,9 @@ #define _GCONV_H 1 #include <features.h> -#define __need_mbstate_t -#define __need_wint_t -#include <wchar.h> +#include <bits/types/__mbstate_t.h> +#include <bits/types/wint_t.h> + #define __need_size_t #define __need_wchar_t #include <stddef.h> @@ -139,7 +139,7 @@ typedef struct __gconv_info { size_t __nsteps; struct __gconv_step *__steps; - __extension__ struct __gconv_step_data __data __flexarr; + __extension__ struct __gconv_step_data __data[0]; } *__gconv_t; /* Transliteration using the locale's data. */ diff --git a/iconv/gconv_builtin.c b/iconv/gconv_builtin.c index 3bd4afa6f9..57dc80f36f 100644 --- a/iconv/gconv_builtin.c +++ b/iconv/gconv_builtin.c @@ -1,5 +1,5 @@ /* Table for builtin transformation mapping. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -59,7 +59,6 @@ static const struct builtin_map void -internal_function __gconv_get_builtin_trans (const char *name, struct __gconv_step *step) { size_t cnt; diff --git a/iconv/gconv_builtin.h b/iconv/gconv_builtin.h index 856d0a9c6f..b8bed3e866 100644 --- a/iconv/gconv_builtin.h +++ b/iconv/gconv_builtin.h @@ -1,5 +1,5 @@ /* Builtin transformations. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -84,7 +84,7 @@ BUILTIN_ALIAS ("OSF00010020//", "ANSI_X3.4-1968//") BUILTIN_TRANSFORMATION ("ANSI_X3.4-1968//", "INTERNAL", 1, "=ascii->INTERNAL", __gconv_transform_ascii_internal, __gconv_btwoc_ascii, - 4, 4, 1, 1) + 1, 1, 4, 4) BUILTIN_TRANSFORMATION ("INTERNAL", "ANSI_X3.4-1968//", 1, "=INTERNAL->ascii", __gconv_transform_internal_ascii, NULL, 4, 4, 1, 1) diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index 4103de10a7..0b114aa2db 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -1,5 +1,5 @@ /* Cache handling for iconv modules. - Copyright (C) 2001-2016 Free Software Foundation, Inc. + Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001. @@ -45,7 +45,6 @@ __gconv_get_cache (void) int -internal_function __gconv_load_cache (void) { int fd; @@ -59,7 +58,7 @@ __gconv_load_cache (void) return -1; /* See whether the cache file exists. */ - fd = open_not_cancel (GCONV_MODULES_CACHE, O_RDONLY, 0); + fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY, 0); if (__builtin_expect (fd, 0) == -1) /* Not available. */ return -1; @@ -71,7 +70,7 @@ __gconv_load_cache (void) || (size_t) st.st_size < sizeof (struct gconvcache_header)) { close_and_exit: - close_not_cancel_no_status (fd); + __close_nocancel_nostatus (fd); return -1; } @@ -108,7 +107,7 @@ __gconv_load_cache (void) } /* We don't need the file descriptor anymore. */ - close_not_cancel_no_status (fd); + __close_nocancel_nostatus (fd); /* Check the consistency. */ header = (struct gconvcache_header *) gconv_cache; @@ -142,7 +141,6 @@ __gconv_load_cache (void) static int -internal_function find_module_idx (const char *str, size_t *idxp) { unsigned int idx; @@ -181,7 +179,6 @@ find_module_idx (const char *str, size_t *idxp) #ifndef STATIC_GCONV static int -internal_function find_module (const char *directory, const char *filename, struct __gconv_step *result) { @@ -207,17 +204,16 @@ find_module (const char *directory, const char *filename, result->__data = NULL; /* Call the init function. */ - if (result->__init_fct != NULL) - { - __gconv_init_fct init_fct = result->__init_fct; + __gconv_init_fct init_fct = result->__init_fct; #ifdef PTR_DEMANGLE - PTR_DEMANGLE (init_fct); + PTR_DEMANGLE (init_fct); #endif + if (init_fct != NULL) + { status = DL_CALL_FCT (init_fct, (result)); #ifdef PTR_MANGLE - if (result->__btowc_fct != NULL) - PTR_MANGLE (result->__btowc_fct); + PTR_MANGLE (result->__btowc_fct); #endif } } @@ -228,7 +224,6 @@ find_module (const char *directory, const char *filename, int -internal_function __gconv_compare_alias_cache (const char *name1, const char *name2, int *result) { size_t name1_idx; @@ -248,7 +243,6 @@ __gconv_compare_alias_cache (const char *name1, const char *name2, int *result) int -internal_function __gconv_lookup_cache (const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps, int flags) { @@ -450,7 +444,6 @@ __gconv_lookup_cache (const char *toset, const char *fromset, /* Free memory allocated for the transformation record. */ void -internal_function __gconv_release_cache (struct __gconv_step *steps, size_t nsteps) { if (gconv_cache != NULL) diff --git a/iconv/gconv_charset.h b/iconv/gconv_charset.h index 95cbce7b63..123e2a62ce 100644 --- a/iconv/gconv_charset.h +++ b/iconv/gconv_charset.h @@ -1,5 +1,5 @@ /* Charset name normalization. - Copyright (C) 2001-2016 Free Software Foundation, Inc. + Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001. diff --git a/iconv/gconv_close.c b/iconv/gconv_close.c index c9a61773b2..7fbe657bb9 100644 --- a/iconv/gconv_close.c +++ b/iconv/gconv_close.c @@ -1,5 +1,5 @@ /* Release any resource associated with given conversion descriptor. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -23,7 +23,6 @@ int -internal_function __gconv_close (__gconv_t cd) { struct __gconv_step *srunp; diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index e23518846c..f173cde71b 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -1,5 +1,5 @@ /* Handle configuration data. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -99,7 +99,6 @@ const char *__gconv_path_envvar; /* Test whether there is already a matching module known. */ static int -internal_function detect_conflict (const char *alias) { struct gconv_module *node = __gconv_modules_db; @@ -183,7 +182,6 @@ add_alias (char *rp, void *modules) /* Insert a data structure for a new module in the search tree. */ static void -internal_function insert_module (struct gconv_module *newp, int tobefreed) { struct gconv_module **rootp = &__gconv_modules_db; @@ -242,7 +240,6 @@ insert_module (struct gconv_module *newp, int tobefreed) /* Add new module. */ static void -internal_function add_module (char *rp, const char *directory, size_t dir_len, void **modules, size_t *nmodules, int modcounter) { @@ -357,7 +354,6 @@ add_module (char *rp, const char *directory, size_t dir_len, void **modules, /* Read the next configuration file. */ static void -internal_function read_conf_file (const char *filename, const char *directory, size_t dir_len, void **modules, size_t *nmodules) { @@ -378,7 +374,7 @@ read_conf_file (const char *filename, const char *directory, size_t dir_len, /* Process the known entries of the file. Comments start with `#' and end with the end of the line. Empty lines are ignored. */ - while (!feof_unlocked (fp)) + while (!__feof_unlocked (fp)) { char *rp, *endp, *word; ssize_t n = __getdelim (&line, &line_len, '\n', fp); @@ -425,7 +421,6 @@ read_conf_file (const char *filename, const char *directory, size_t dir_len, /* Determine the directories we are looking for data in. */ void -internal_function __gconv_get_path (void) { struct path_elem *result; diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c index a441100df4..66e095d8c7 100644 --- a/iconv/gconv_db.c +++ b/iconv/gconv_db.c @@ -1,5 +1,5 @@ /* Provide access to the collection of available transformation modules. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -121,7 +121,6 @@ static void *known_derivations; /* Look up whether given transformation was already requested before. */ static int -internal_function derivation_lookup (const char *fromset, const char *toset, struct __gconv_step **handle, size_t *nsteps) { @@ -143,7 +142,6 @@ derivation_lookup (const char *fromset, const char *toset, /* Add new derivation to list of known ones. */ static void -internal_function add_derivation (const char *fromset, const char *toset, struct __gconv_step *handle, size_t nsteps) { @@ -180,15 +178,14 @@ free_derivation (void *p) for (cnt = 0; cnt < deriv->nsteps; ++cnt) if (deriv->steps[cnt].__counter > 0 - && deriv->steps[cnt].__end_fct != NULL) + && deriv->steps[cnt].__shlib_handle != NULL) { - assert (deriv->steps[cnt].__shlib_handle != NULL); - __gconv_end_fct end_fct = deriv->steps[cnt].__end_fct; #ifdef PTR_DEMANGLE PTR_DEMANGLE (end_fct); #endif - DL_CALL_FCT (end_fct, (&deriv->steps[cnt])); + if (end_fct != NULL) + DL_CALL_FCT (end_fct, (&deriv->steps[cnt])); } /* Free the name strings. */ @@ -205,23 +202,18 @@ free_derivation (void *p) /* Decrement the reference count for a single step in a steps array. */ void -internal_function __gconv_release_step (struct __gconv_step *step) { /* Skip builtin modules; they are not reference counted. */ if (step->__shlib_handle != NULL && --step->__counter == 0) { /* Call the destructor. */ - if (step->__end_fct != NULL) - { - assert (step->__shlib_handle != NULL); - - __gconv_end_fct end_fct = step->__end_fct; + __gconv_end_fct end_fct = step->__end_fct; #ifdef PTR_DEMANGLE - PTR_DEMANGLE (end_fct); + PTR_DEMANGLE (end_fct); #endif - DL_CALL_FCT (end_fct, (step)); - } + if (end_fct != NULL) + DL_CALL_FCT (end_fct, (step)); #ifndef STATIC_GCONV /* Release the loaded module. */ @@ -235,7 +227,6 @@ __gconv_release_step (struct __gconv_step *step) } static int -internal_function gen_steps (struct derivation_step *best, const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps) { @@ -313,29 +304,30 @@ gen_steps (struct derivation_step *best, const char *toset, /* Call the init function. */ __gconv_init_fct init_fct = result[step_cnt].__init_fct; - if (init_fct != NULL) - { - assert (result[step_cnt].__shlib_handle != NULL); - # ifdef PTR_DEMANGLE - PTR_DEMANGLE (init_fct); + PTR_DEMANGLE (init_fct); # endif + if (init_fct != NULL) + { status = DL_CALL_FCT (init_fct, (&result[step_cnt])); if (__builtin_expect (status, __GCONV_OK) != __GCONV_OK) { failed = 1; - /* Make sure we unload this modules. */ - --step_cnt; + /* Do not call the end function because the init + function has failed. */ result[step_cnt].__end_fct = NULL; +# ifdef PTR_MANGLE + PTR_MANGLE (result[step_cnt].__end_fct); +# endif + /* Make sure we unload this module. */ + --step_cnt; break; } - + } # ifdef PTR_MANGLE - if (result[step_cnt].__btowc_fct != NULL) - PTR_MANGLE (result[step_cnt].__btowc_fct); + PTR_MANGLE (result[step_cnt].__btowc_fct); # endif - } } else #endif @@ -374,7 +366,6 @@ gen_steps (struct derivation_step *best, const char *toset, #ifndef STATIC_GCONV static int -internal_function increment_counter (struct __gconv_step *steps, size_t nsteps) { /* Increment the user counter. */ @@ -411,20 +402,17 @@ increment_counter (struct __gconv_step *steps, size_t nsteps) /* These settings can be overridden by the init function. */ step->__btowc_fct = NULL; - } - /* Call the init function. */ - __gconv_init_fct init_fct = step->__init_fct; - if (init_fct != NULL) - { + /* Call the init function. */ + __gconv_init_fct init_fct = step->__init_fct; #ifdef PTR_DEMANGLE PTR_DEMANGLE (init_fct); #endif - DL_CALL_FCT (init_fct, (step)); + if (init_fct != NULL) + DL_CALL_FCT (init_fct, (step)); #ifdef PTR_MANGLE - if (step->__btowc_fct != NULL) - PTR_MANGLE (step->__btowc_fct); + PTR_MANGLE (step->__btowc_fct); #endif } } @@ -437,7 +425,6 @@ increment_counter (struct __gconv_step *steps, size_t nsteps) /* The main function: find a possible derivation from the `fromset' (either the given name or the alias) to the `toset' (again with alias). */ static int -internal_function find_derivation (const char *toset, const char *toset_expand, const char *fromset, const char *fromset_expand, struct __gconv_step **handle, size_t *nsteps) @@ -717,7 +704,6 @@ do_lookup_alias (const char *name) int -internal_function __gconv_compare_alias (const char *name1, const char *name2) { int result; @@ -734,7 +720,6 @@ __gconv_compare_alias (const char *name1, const char *name2) int -internal_function __gconv_find_transform (const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps, int flags) @@ -800,7 +785,6 @@ __gconv_find_transform (const char *toset, const char *fromset, /* Release the entries of the modules list. */ int -internal_function __gconv_close_transform (struct __gconv_step *steps, size_t nsteps) { int result = __GCONV_OK; @@ -829,7 +813,7 @@ __gconv_close_transform (struct __gconv_step *steps, size_t nsteps) /* Free the modules mentioned. */ static void -internal_function __libc_freeres_fn_section +__libc_freeres_fn_section free_modules_db (struct gconv_module *node) { if (node->left != NULL) diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c index 4e9dfea437..de00e1319d 100644 --- a/iconv/gconv_dl.c +++ b/iconv/gconv_dl.c @@ -1,5 +1,5 @@ /* Handle loading/unloading of shared object for transformation. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -64,7 +64,6 @@ known_compare (const void *p1, const void *p2) /* Open the gconv database if necessary. A non-negative return value means success. */ struct __gconv_loaded_object * -internal_function __gconv_find_shlib (const char *name) { struct __gconv_loaded_object *found; @@ -131,10 +130,8 @@ __gconv_find_shlib (const char *name) #ifdef PTR_MANGLE PTR_MANGLE (found->fct); - if (found->init_fct != NULL) - PTR_MANGLE (found->init_fct); - if (found->end_fct != NULL) - PTR_MANGLE (found->end_fct); + PTR_MANGLE (found->init_fct); + PTR_MANGLE (found->end_fct); #endif /* We have succeeded in loading the shared object. */ @@ -185,7 +182,6 @@ do_release_shlib (void *nodep, VISIT value, int level) /* Notify system that a shared object is not longer needed. */ void -internal_function __gconv_release_shlib (struct __gconv_loaded_object *handle) { /* Urgh, this is ugly but we have no other possibility. */ diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h index 7201ab657e..3742557cae 100644 --- a/iconv/gconv_int.h +++ b/iconv/gconv_int.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. +/* Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -157,11 +157,11 @@ __libc_lock_define (extern, __gconv_lock attribute_hidden) /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */ extern int __gconv_open (const char *toset, const char *fromset, __gconv_t *handle, int flags) - internal_function; + attribute_hidden; /* Free resources associated with transformation descriptor CD. */ extern int __gconv_close (__gconv_t cd) - internal_function; + attribute_hidden; /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF according to rules described by CD and place up to *OUTBYTESLEFT @@ -170,36 +170,37 @@ extern int __gconv_close (__gconv_t cd) extern int __gconv (__gconv_t cd, const unsigned char **inbuf, const unsigned char *inbufend, unsigned char **outbuf, unsigned char *outbufend, size_t *irreversible) - internal_function; + attribute_hidden; /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing the single steps necessary for transformation from FROMSET to TOSET. */ extern int __gconv_find_transform (const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps, int flags) - internal_function; + attribute_hidden; /* Search for transformation in cache data. */ extern int __gconv_lookup_cache (const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps, int flags) - internal_function; + attribute_hidden; /* Compare the two name for whether they are after alias expansion the same. This function uses the cache and fails if none is loaded. */ extern int __gconv_compare_alias_cache (const char *name1, const char *name2, - int *result) internal_function; + int *result) + attribute_hidden; /* Free data associated with a step's structure. */ extern void __gconv_release_step (struct __gconv_step *step) - internal_function; + attribute_hidden; /* Read all the configuration data and cache it. */ extern void __gconv_read_conf (void) attribute_hidden; /* Try to read module cache file. */ -extern int __gconv_load_cache (void) internal_function; +extern int __gconv_load_cache (void) attribute_hidden; /* Retrieve pointer to internal cache. */ extern void *__gconv_get_cache (void); @@ -211,7 +212,7 @@ extern struct gconv_module *__gconv_get_modules_db (void); extern void *__gconv_get_alias_db (void); /* Determine the directories we are looking in. */ -extern void __gconv_get_path (void) internal_function; +extern void __gconv_get_path (void) attribute_hidden; /* Comparison function to search alias. */ extern int __gconv_alias_compare (const void *p1, const void *p2) @@ -221,33 +222,33 @@ extern int __gconv_alias_compare (const void *p1, const void *p2) cause the code to be unloaded. */ extern int __gconv_close_transform (struct __gconv_step *steps, size_t nsteps) - internal_function; + attribute_hidden; /* Free all resources allocated for the transformation record when using the cache. */ extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps) - internal_function; + attribute_hidden; /* Load shared object named by NAME. If already loaded increment reference count. */ extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name) - internal_function; + attribute_hidden; /* Release shared object. If no further reference is available unload the object. */ extern void __gconv_release_shlib (struct __gconv_loaded_object *handle) - internal_function; + attribute_hidden; /* Fill STEP with information about builtin module with NAME. */ extern void __gconv_get_builtin_trans (const char *name, struct __gconv_step *step) - internal_function; + attribute_hidden; libc_hidden_proto (__gconv_transliterate) /* If NAME is an codeset alias expand it. */ extern int __gconv_compare_alias (const char *name1, const char *name2) - internal_function; + attribute_hidden; /* Builtin transformations. */ diff --git a/iconv/gconv_open.c b/iconv/gconv_open.c index f662872a5d..f739561f6e 100644 --- a/iconv/gconv_open.c +++ b/iconv/gconv_open.c @@ -1,5 +1,5 @@ /* Find matching transformation algorithms and initialize steps. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -27,7 +27,6 @@ int -internal_function __gconv_open (const char *toset, const char *fromset, __gconv_t *handle, int flags) { diff --git a/iconv/gconv_simple.c b/iconv/gconv_simple.c index 5412bd6f65..506c92caf2 100644 --- a/iconv/gconv_simple.c +++ b/iconv/gconv_simple.c @@ -1,5 +1,5 @@ /* Simple transformations functions. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -638,6 +638,8 @@ ucs4le_internal_loop (struct __gconv_step *step, continue; } + *inptrp = inptr; + *outptrp = outptr; return __GCONV_ILLEGAL_INPUT; } @@ -890,7 +892,8 @@ ucs4le_internal_loop_single (struct __gconv_step *step, if (__glibc_likely (wc < 0x80)) \ /* It's an one byte sequence. */ \ *outptr++ = (unsigned char) wc; \ - else if (__glibc_likely (wc <= 0x7fffffff)) \ + else if (__glibc_likely (wc <= 0x7fffffff \ + && (wc < 0xd800 || wc > 0xdfff))) \ { \ size_t step; \ unsigned char *start; \ diff --git a/iconv/gconv_trans.c b/iconv/gconv_trans.c index 91ec843860..d20ae66384 100644 --- a/iconv/gconv_trans.c +++ b/iconv/gconv_trans.c @@ -1,5 +1,5 @@ /* Transliteration using the locale's data. - Copyright (C) 2000-2016 Free Software Foundation, Inc. + Copyright (C) 2000-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000. diff --git a/iconv/iconv.c b/iconv/iconv.c index 839e17b2af..c3e472a9c8 100644 --- a/iconv/iconv.c +++ b/iconv/iconv.c @@ -1,6 +1,6 @@ /* Convert characters in input buffer using conversion descriptor to output buffer. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/iconv/iconv.h b/iconv/iconv.h index 0c95c98301..63d78336ad 100644 --- a/iconv/iconv.h +++ b/iconv/iconv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2016 Free Software Foundation, Inc. +/* Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/iconv/iconv_charmap.c b/iconv/iconv_charmap.c index 999d21b658..65894199db 100644 --- a/iconv/iconv_charmap.c +++ b/iconv/iconv_charmap.c @@ -1,5 +1,5 @@ /* Convert using charmaps and possibly iconv(). - Copyright (C) 2001-2016 Free Software Foundation, Inc. + Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. diff --git a/iconv/iconv_close.c b/iconv/iconv_close.c index 50ae0cde45..6d34b360d2 100644 --- a/iconv/iconv_close.c +++ b/iconv/iconv_close.c @@ -1,5 +1,5 @@ /* Release any resource associated with given conversion descriptor. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/iconv/iconv_open.c b/iconv/iconv_open.c index ebd46e2103..9f5c32c020 100644 --- a/iconv/iconv_open.c +++ b/iconv/iconv_open.c @@ -1,5 +1,5 @@ /* Get descriptor for character set conversion. - Copyright (C) 1997-2016 Free Software Foundation, Inc. + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c index 1ec70abcae..52e9d3f3dd 100644 --- a/iconv/iconv_prog.c +++ b/iconv/iconv_prog.c @@ -1,5 +1,5 @@ /* Convert text in given files from the specified from-set to the to-set. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -97,9 +97,6 @@ static const char *to_code = ""; /* File to write output to. If NULL write to stdout. */ static const char *output_file; -/* Nonzero if verbose ouput is wanted. */ -int verbose; - /* Nonzero if list of all coded character sets is wanted. */ static int list; @@ -113,7 +110,7 @@ static int process_fd (iconv_t cd, int fd, FILE **output, const char *output_file); static int process_file (iconv_t cd, FILE *input, FILE **output, const char *output_file); -static void print_known_names (void) internal_function; +static void print_known_names (void); int @@ -426,7 +423,7 @@ print_version (FILE *stream, struct argp_state *state) Copyright (C) %s Free Software Foundation, Inc.\n\ This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2016"); +"), "2018"); fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); } @@ -712,7 +709,6 @@ do_print (const void *nodep, VISIT value, int level) } static void -internal_function add_known_names (struct gconv_module *node) { if (node->left != NULL) @@ -756,7 +752,6 @@ insert_cache (void) static void -internal_function print_known_names (void) { iconv_t h; diff --git a/iconv/iconv_prog.h b/iconv/iconv_prog.h index c6c289521f..3273ad6125 100644 --- a/iconv/iconv_prog.h +++ b/iconv/iconv_prog.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. +/* Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2001. @@ -20,11 +20,9 @@ #define _ICONV_PROG_H 1 #include <stdio.h> -#include <charmap.h> - -/* Nonzero if verbose ouput is wanted. */ -extern int verbose; +#include <charmap.h> +#include <record-status.h> /* If nonzero omit invalid character from output. */ extern int omit_invalid; diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c index 05674de326..d5e8e71423 100644 --- a/iconv/iconvconfig.c +++ b/iconv/iconvconfig.c @@ -1,5 +1,5 @@ /* Generate fastloading iconv module configuration files. - Copyright (C) 2000-2016 Free Software Foundation, Inc. + Copyright (C) 2000-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2000. @@ -397,7 +397,7 @@ print_version (FILE *stream, struct argp_state *state) Copyright (C) %s Free Software Foundation, Inc.\n\ This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ -"), "2016"); +"), "2018"); fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); } @@ -566,7 +566,6 @@ new_module (const char *fromname, size_t fromlen, const char *toname, /* Add new module. */ static void -internal_function add_module (char *rp, const char *directory) { /* We expect now diff --git a/iconv/iconvconfig.h b/iconv/iconvconfig.h index a08aed9691..2f39f08a80 100644 --- a/iconv/iconvconfig.h +++ b/iconv/iconvconfig.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2016 Free Software Foundation, Inc. +/* Copyright (C) 2000-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2000. diff --git a/iconv/loop.c b/iconv/loop.c index c432168eef..d571b593c7 100644 --- a/iconv/loop.c +++ b/iconv/loop.c @@ -1,5 +1,5 @@ /* Conversion loop frame work. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -56,7 +56,7 @@ #include <sys/param.h> /* For MIN. */ #define __need_size_t #include <stddef.h> -#include <libc-internal.h> +#include <libc-diag.h> /* We have to provide support for machines which are not able to handled unaligned memory accesses. Some of the character encodings have @@ -254,6 +254,16 @@ } +/* With GCC 7 when compiling with -Os for 32-bit s390 the compiler + warns that the variable 'ch', in the definition of BODY in + sysdeps/s390/multiarch/8bit-generic.c, may be used uninitialized in + the call to UNICODE_TAG_HANDLER in that macro. This variable is + actually always initialized before use, in the prior loop if INDEX + is nonzero and in the following 'if' if INDEX is zero. That code + has a comment referencing this diagnostic disabling; updates in one + place may require updates in the other. */ +DIAG_PUSH_NEEDS_COMMENT; +DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized"); /* Handling of Unicode 3.1 TAG characters. Unicode recommends "If language codes are not relevant to the particular processing operation, then they should be ignored." This macro is usually @@ -267,6 +277,7 @@ continue; \ } \ } +DIAG_POP_NEEDS_COMMENT; /* The function returns the status, as defined in gconv.h. */ diff --git a/iconv/skeleton.c b/iconv/skeleton.c index a15f8b1d0b..fa79930523 100644 --- a/iconv/skeleton.c +++ b/iconv/skeleton.c @@ -1,5 +1,5 @@ /* Skeleton for a conversion module. - Copyright (C) 1998-2016 Free Software Foundation, Inc. + Copyright (C) 1998-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. diff --git a/iconv/strtab.c b/iconv/strtab.c index e8fef047e2..f49aaf2c7d 100644 --- a/iconv/strtab.c +++ b/iconv/strtab.c @@ -1,5 +1,5 @@ /* C string table handling. - Copyright (C) 2000-2016 Free Software Foundation, Inc. + Copyright (C) 2000-2018 Free Software Foundation, Inc. Written by Ulrich Drepper <drepper@redhat.com>, 2000. This program is free software; you can redistribute it and/or modify diff --git a/iconv/test-gconv-modules b/iconv/test-gconv-modules new file mode 100644 index 0000000000..081158b8ca --- /dev/null +++ b/iconv/test-gconv-modules @@ -0,0 +1,23 @@ +# Test modules for gconv. +# Copyright (C) 2017-2018 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# <http://www.gnu.org/licenses/>. + +# To activate these modules, tests need to put a directory with the +# modules and a copy of this file (under the name gconv-modules) on +# GCONV_PATH. + +module TST-GCONV-INIT-FAILURE// UTF-8// tst-gconv-init-failure-mod diff --git a/iconv/tst-gconv-init-failure-mod.c b/iconv/tst-gconv-init-failure-mod.c new file mode 100644 index 0000000000..565057ef78 --- /dev/null +++ b/iconv/tst-gconv-init-failure-mod.c @@ -0,0 +1,49 @@ +/* Test gconv module for tst-gconv-init-failure. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <gconv.h> +#include <support/check.h> +#include <support/support.h> + +int +gconv (struct __gconv_step *step, + struct __gconv_step_data *data, + const unsigned char **inptrp, + const unsigned char *inend, + unsigned char **outbufstart, size_t *irreversible, + int do_flush, int consume_incomplete) +{ + FAIL_EXIT1 ("gconv called"); + return __GCONV_INTERNAL_ERROR; +} + +int +gconv_init (struct __gconv_step *ignored) +{ + write_message ("info: gconv_init called, returning error\n"); + errno = ENOMEM; + return __GCONV_NOMEM; +} + +int +gconv_end (struct __gconv_step *ignored) +{ + FAIL_EXIT1 ("gconv_end called"); + return __GCONV_INTERNAL_ERROR; +} diff --git a/iconv/tst-gconv-init-failure.c b/iconv/tst-gconv-init-failure.c new file mode 100644 index 0000000000..6ea5b7f501 --- /dev/null +++ b/iconv/tst-gconv-init-failure.c @@ -0,0 +1,58 @@ +/* Check that module __end_fct is not invoked when the init function fails. + Copyright (C) 2017-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <iconv.h> +#include <libgen.h> +#include <stdio.h> +#include <stdlib.h> +#include <support/check.h> +#include <support/support.h> +#include <support/test-driver.h> +#include <sys/auxv.h> + +/* Test GCONV_PATH to the directory containing the program + executable. */ +static void +activate_test_gconv_modules (void) +{ + unsigned long ptr = getauxval (AT_EXECFN); + if (ptr == 0) + { + printf ("warning: AT_EXECFN not support, cannot run test\n"); + exit (EXIT_UNSUPPORTED); + } + char *test_program_directory = dirname (xstrdup ((const char *) ptr)); + TEST_VERIFY (setenv ("GCONV_PATH", test_program_directory, 1) == 0); + free (test_program_directory); +} + +static int +do_test (void) +{ + activate_test_gconv_modules (); + + TEST_VERIFY (iconv_open ("UTF-8", "tst-gconv-init-failure//") + == (iconv_t) -1); + if (errno != ENOMEM) + FAIL_EXIT1 ("unexpected iconv_open error: %m"); + + return 0; +} + +#include <support/test-driver.c> diff --git a/iconv/tst-iconv2.c b/iconv/tst-iconv2.c index a2b42ba816..00712a8985 100644 --- a/iconv/tst-iconv2.c +++ b/iconv/tst-iconv2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2016 Free Software Foundation, Inc. +/* Copyright (C) 2001-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001. diff --git a/iconv/tst-iconv5.c b/iconv/tst-iconv5.c index 414905e0a0..92ccb246f9 100644 --- a/iconv/tst-iconv5.c +++ b/iconv/tst-iconv5.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2016 Free Software Foundation, Inc. +/* Copyright (C) 2004-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by GOTO Masanori <gotom@debian.or.jp>, 2004 diff --git a/iconv/tst-iconv6.c b/iconv/tst-iconv6.c new file mode 100644 index 0000000000..4cda02551d --- /dev/null +++ b/iconv/tst-iconv6.c @@ -0,0 +1,118 @@ +/* Testing ucs4le_internal_loop() in gconv_simple.c. + Copyright (C) 2016-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <inttypes.h> +#include <iconv.h> +#include <byteswap.h> +#include <endian.h> + +static int +do_test (void) +{ + iconv_t cd; + char *inptr; + size_t inlen; + char *outptr; + size_t outlen; + size_t n; + int e; + int result = 0; + +#if __BYTE_ORDER == __BIG_ENDIAN + /* On big-endian machines, ucs4le_internal_loop() swaps the bytes before + error checking. Thus the input values has to be swapped. */ +# define VALUE(val) bswap_32 (val) +#else +# define VALUE(val) val +#endif + uint32_t inbuf[3] = { VALUE (0x41), VALUE (0x80000000), VALUE (0x42) }; + uint32_t outbuf[3] = { 0, 0, 0 }; + + cd = iconv_open ("WCHAR_T", "UCS-4LE"); + if (cd == (iconv_t) -1) + { + printf ("cannot convert from UCS4LE to wchar_t: %m\n"); + return 1; + } + + inptr = (char *) inbuf; + inlen = sizeof (inbuf); + outptr = (char *) outbuf; + outlen = sizeof (outbuf); + + n = iconv (cd, &inptr, &inlen, &outptr, &outlen); + e = errno; + + if (n != (size_t) -1) + { + printf ("incorrect iconv() return value: %zd, expected -1\n", n); + result = 1; + } + + if (e != EILSEQ) + { + printf ("incorrect error value: %s, expected %s\n", + strerror (e), strerror (EILSEQ)); + result = 1; + } + + if (inptr != (char *) &inbuf[1]) + { + printf ("inptr=0x%p does not point to invalid character! Expected=0x%p\n" + , inptr, &inbuf[1]); + result = 1; + } + + if (inlen != sizeof (inbuf) - sizeof (uint32_t)) + { + printf ("inlen=%zd != %zd\n" + , inlen, sizeof (inbuf) - sizeof (uint32_t)); + result = 1; + } + + if (outptr != (char *) &outbuf[1]) + { + printf ("outptr=0x%p does not point to invalid character in inbuf! " + "Expected=0x%p\n" + , outptr, &outbuf[1]); + result = 1; + } + + if (outlen != sizeof (inbuf) - sizeof (uint32_t)) + { + printf ("outlen=%zd != %zd\n" + , outlen, sizeof (outbuf) - sizeof (uint32_t)); + result = 1; + } + + if (outbuf[0] != 0x41 || outbuf[1] != 0 || outbuf[2] != 0) + { + puts ("Characters conversion is incorrect!"); + result = 1; + } + + iconv_close (cd); + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |