Bruno Haible [Thu, 30 Nov 2023 07:43:16 +0000 (08:43 +0100)]
xgettext: Refactor the formatstring code.
* gettext-tools/src/xg-formatstring.h (NXFORMATS, XFORMAT_PRIMARY,
XFORMAT_SECONDARY, XFORMAT_TERTIARY, XFORMAT_FOURTH): New macros.
(current_formatstring_parser1, current_formatstring_parser2,
current_formatstring_parser3, current_formatstring_parser4): Remove
declarations.
(current_formatstring_parser): New declaration.
* gettext-tools/src/xg-formatstring.c (current_formatstring_parser1,
current_formatstring_parser2, current_formatstring_parser3,
current_formatstring_parser4): Remove variables.
(current_formatstring_parser): New variable.
* gettext-tools/src/xg-arglist-context.h: Include xg-formatstring.h.
(struct formatstring_context_ty): New type.
(struct flag_context_ty): Replace individual fields with an array.
(flag_context_list_table_add): Rename parameter 'index' to 'fi'.
* gettext-tools/src/xg-arglist-context.c (null_context, passthrough_context):
Update.
(inherited_context): Loop over the four formatstring types.
(passthrough_context_circular_list): Update.
(set_flags_for_formatstring_type): Simplify.
(flag_context_list_table_add): Rename parameter 'index' to 'fi'.
* gettext-tools/src/xg-arglist-parser.c (arglist_parser_done): Update.
* gettext-tools/src/xg-message.c (set_format_flags_from_context): Loop over the
four formatstring types.
(is_relevant): New function.
(decide_is_format, remember_a_message_plural): Use it.
* gettext-tools/src/xgettext.c (struct extractor_ty): Replace individual fields
with an array.
(main): Update.
(flag_context_list_table_insert): Rename parameter 'index' to 'fi'.
(xgettext_record_flag): Use XFORMAT_* macros.
(extract_from_file): Loop over the four formatstring types.
(recognize_qt_formatstrings): Update.
(language_to_extractor): Use XFORMAT_* macros and a loop.
Bruno Haible [Thu, 30 Nov 2023 07:24:18 +0000 (08:24 +0100)]
Fix clang -Wunused-function warnings.
* gettext-runtime/src/envsubst.c: Include attribute.h.
(string_list_member, string_list_destroy): Mark as MAYBE_UNUSED.
* gettext-tools/src/format-scheme.c: Include attribute.h.
(II): Mark as MAYBE_UNUSED.
* gettext-tools/src/msgl-fsearch.c: Include attribute.h.
(add_index): Mark as MAYBE_UNUSED.
* gettext-tools/src/po-lex.c: Include attribute.h.
(mb_isnul, mb_cmp, mb_equal, mb_isascii, mb_putc, mb_setascii): Mark as
MAYBE_UNUSED.
* gettext-tools/src/write-qt.c: Include attribute.h.
(write_u16): Mark as MAYBE_UNUSED.
* gettext-tools/src/x-awk.c (free_token): Mark as MAYBE_UNUSED.
* gettext-tools/src/x-python.c (phase0_ungetc): Mark as MAYBE_UNUSED.
Bruno Haible [Fri, 17 Nov 2023 11:46:18 +0000 (12:46 +0100)]
gettext.m4: Recognize a statically built libintl on macOS and AIX.
Reported by David Edelsohn <dje.gcc@gmail.com> in
<https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636558.html>.
* gettext-runtime/m4/gettext.m4 (AM_GNU_GETTEXT): In the
"checking for GNU gettext in libintl..." test, add also the special
system library dependencies needed on macOS and AIX.
Bruno Haible [Fri, 17 Nov 2023 11:40:54 +0000 (12:40 +0100)]
build: Fix a build issue on AIX.
How to reproduce:
$ cd gettext-20231111
$ ~/build-64-gcc --disable-shared
$ (cd build-64-gcc && gmake install)
$ cd ..
$ cd gettext-0.22.3
$ ~/build-64-gcc
=> Fails with "ERROR: Undefined symbol: .syntax_check_message_list"
because the link uses $PREFIX/lib/libgettextsrc.a, which is a non-shared
library that does not export 'syntax_check_message_list'.
* gettext-tools/configure.ac (INSTALL_PRIVATE_LIBRARIES): New conditional.
* gettext-tools/src/Makefile.am (noinst_LTLIBRARIES): Define as alternative to
lib_LTLIBRARIES.
(install-exec-clean): Remove rule.
* gettext-tools/gnulib-lib/Makefile.am (lib_LTLIBRARIES): Initialize.
* gnulib-local/modules/gettext-tools-misc (Makefile.am): Define
noinst_LTLIBRARIES as alternative to lib_LTLIBRARIES. Remove
'install-exec-clean' rule.
* gettext-tools/src/po-gram-gen.y: Request a pure parser.
* gettext-tools/src/po-lex.h (po_gram_lex): Add lval parameter.
* gettext-tools/src/po-lex.c (po_gram_lex): Add lval parameter. Store the result
in *lval instead of in po_gram_lval.
* gettext-tools/woe32dll/gettextsrc-exports.c: Remove po_gram_lval.
Bruno Haible [Sat, 11 Nov 2023 15:48:16 +0000 (16:48 +0100)]
libgettextpo: Remove static variable 'width.0'.
* gnulib-local/lib/xerror.h: Include <stddef.h>.
(multiline_warning, multiline_error): Change return type to size_t. Don't
suggest to pass a NULL prefix.
(multiline_append): New declaration.
* gnulib-local/lib/xerror.c (multiline_internal): New function, extracted from
multiline_warning.
(multiline_warning, multiline_error): Reject a NULL prefix. Call
multiline_internal.
(multiline_append): New function.
* gettext-tools/src/msgl-charset.c (compare_po_locale_charsets): Invoke
multiline_append instead of multiline_warning with NULL argument.
* gettext-tools/src/msgfmt.c (msgfmt_parse_debrief): Invoke multiline_append
instead of multiline_error with NULL argument.
* gettext-tools/src/po-error.c (void_multiline_warning, void_multiline_error):
New functions.
(po_multiline_warning, po_multiline_error): Use them as initializer.
* gettext-tools/libgettextpo/gettext-po.c (void_multiline_warning,
void_multiline_error): New functions.
(po_file_read_v2, po_file_write): Use them as defaults for po_multiline_warning,
po_multiline_error.
Bruno Haible [Sat, 11 Nov 2023 15:48:13 +0000 (16:48 +0100)]
libgettextpo: Remove static variable 'result.0'.
* gettext-tools/src/write-po.h (make_format_description_string): Change return
type to 'char *'.
* gettext-tools/src/write-po.c (make_format_description_string): Return a
freshly allocated string.
(message_print_comment_flags, message_print_obsolete): Free the result of
make_format_description_string when done.
* gettext-tools/src/write-stringtable.c (write_message): Likewise.
Bruno Haible [Thu, 5 Oct 2023 21:04:32 +0000 (23:04 +0200)]
xgettext: Simplify code that emits diagnostics with error number.
* autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add xstrerror.
(GNULIB_MODULES_LIBGETTEXTPO_OTHER): Add strerror_r-posix.
* gettext-tools/src/x-csharp.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
* gettext-tools/src/x-javascript.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
* gettext-tools/src/x-python.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
Bruno Haible [Sun, 1 Oct 2023 18:18:12 +0000 (20:18 +0200)]
Avoid crash by stack overflow during plural expression evaluation.
* gettext-runtime/intl/plural-exp.h (enum eval_status, struct eval_result): New
types.
(plural_eval): Change return type to 'struct eval_result'.
* gettext-runtime/intl/eval-plural.h (EVAL_MAXDEPTH, OK): New macros.
(plural_eval_recurse): New function, extracted from plural_eval.
(plural_eval): Change return type to 'struct eval_result'. Invoke
plural_eval_recurse.
* gettext-runtime/intl/dcigettext.c (plural_lookup): Update.
* gettext-tools/src/plural-eval.h: Update comment.
* gettext-tools/src/msgl-check.c (plural_expression_histogram): Update.
(check_plural_eval): Update. Fail with an error message if the plural expression
evaluation produced a stack overflow.
* gettext-tools/tests/plural-3: Update.
Bruno Haible [Sun, 1 Oct 2023 18:18:02 +0000 (20:18 +0200)]
tests: Add option --thread to tstgettext, tstngettext.
* gettext-tools/tests/tstgettext.c: Include glthread/thread.h.
(inhibit_added_newline, do_expand): Remove variables.
(long_options): Add --thread option.
(struct worker_context): New type.
(main): Move some local variables into a context. Recognize option --thread.
At the end, invoke worker_thread.
(worker_thread): New function, extracted from main.
* gettext-tools/tests/tstngettext.c: Include glthread/thread.h.
(long_options): Add --thread option.
(struct worker_context): New type.
(main): Move some local variables into a context. Recognize option --thread.
At the end, invoke worker_thread.
(worker_thread): New function, extracted from main.
* gettext-tools/tests/Makefile.am (tstgettext_LDADD, tstngettext_LDADD): Add
gnulib-lib/libtestsgnu.a and $(LIBMULTITHREAD).
Bruno Haible [Sun, 1 Oct 2023 18:16:36 +0000 (20:16 +0200)]
build: Remove redundant -I options from AM_CPPFLAGS.
https://www.gnu.org/software/automake/manual/html_node/Program-Variables.html
documents that -I. -I$(srcdir) and -I$(top_builddir) (for config.h)
are already part of Automake's $(DEFAULT_INCLUDES), which is used
before $(AM_CPPFLAGS).
Bruno Haible [Sat, 30 Sep 2023 18:03:47 +0000 (20:03 +0200)]
intl: Remove use of alloca() for wdirname handling.
* autogen.sh (GNULIB_MODULES_LIBINTL): Add wgetcwd-lgpl.
* gettext-runtime/intl/dcigettext.c: Include <wchar.h>.
(DCIGETTEXT): Allocate resolved_wdirname through malloc() instead of through
alloca().
Bruno Haible [Sat, 30 Sep 2023 13:08:26 +0000 (15:08 +0200)]
intl: Merge from glibc.
Apply commits
2017-06-21 Florian Weimer <fweimer@redhat.com>
DCIGETTEXT: Use getcwd, asprintf to construct absolute pathname
and
2018-12-21 Florian Weimer <fweimer@redhat.com>
intl: Do not return NULL on asprintf failure in gettext [BZ #24018]
Bruno Haible [Wed, 20 Sep 2023 09:03:35 +0000 (11:03 +0200)]
Fix intl-7 test failure on Solaris 11.
* gettext-tools/tests/init.cfg (prepare_locale_): Preserve the existing contents
of "$2".
* gettext-tools/tests/intl-7: While calling prepare_locale_, ensure that fr_FR
has higher priority than fr.
Bruno Haible [Mon, 18 Sep 2023 19:28:25 +0000 (21:28 +0200)]
libgettextpo: Fix compilation error on FreeBSD (regression 2023-09-16).
* gettext-tools/libgettextpo/gettext-po.c (po_file_write, po_error_logger,
po_message_check_format): Use orig_error, orig_error_at_line instead of the
error, error_at_line symbols.
* gettext-tools/src/x-perl.c: Ensure the top-level extract_balanced call returns
when a closing paren or bracket is seen.
(token_type_r_any): New enum item.
(prefer_regexp_over_division, extract_balanced): Handle it.
(extract_perl): Pass token_type_r_any instead of token_type_rbrace.
Bruno Haible [Mon, 18 Sep 2023 18:26:48 +0000 (20:26 +0200)]
xgettext: Perl: Add test against unbounded nesting_depth growth.
Reported by Gavin D. Smith <gavinsmith0123@gmail.com> at
<https://lists.gnu.org/archive/html/bug-gettext/2023-07/msg00008.html>
and <https://savannah.gnu.org/bugs/?64552>.
* gettext-tools/tests/xgettext-perl-stackovfl-5: New file.
* gettext-tools/tests/testdata/xg-pl-so-5.pl: New file, taken from
https://git.savannah.gnu.org/gitweb/?p=texinfo.git;a=blob;f=tp/Texinfo/Convert/HTML.pm;hb=c8d9edd94d9b1a3e675e811208d9e66eaf9a7daa
* gettext-tools/tests/Makefile.am (TESTS): Add xgettext-perl-stackovfl-5.
(EXTRA_DIST): Add testdata/xg-pl-so-5.pl.
Bruno Haible [Mon, 18 Sep 2023 18:04:47 +0000 (20:04 +0200)]
xgettext: Perl: Avoid unbounded nesting_depth growth, part 4.
* gettext-tools/src/x-perl.c: Improve parsing of array dereferences.
(extract_variable): After parsing a braced {variable_name}, increment
varbody_length, so as to not parse the following character. If this character
is a closing parenthesis, is would disturb the enclosing extract_balanced call.
Test case:
==========================================
sub in_multi_expanded($)
{
if (@{$self}) {
}
}
==========================================
Bruno Haible [Mon, 18 Sep 2023 17:26:54 +0000 (19:26 +0200)]
xgettext: Perl: Avoid unbounded nesting_depth growth, part 3.
* gettext-tools/src/x-perl.c: Return from extract_balanced when a subroutine's
definition terminates and that subroutine was defined after a declaration that
ended with a semicolon.
(extract_perl): Pass semicolon_delim=true.
Test case:
==========================================
my %a = 4;
sub b
{
}
==========================================
Bruno Haible [Mon, 18 Sep 2023 17:02:01 +0000 (19:02 +0200)]
xgettext: Perl: Avoid unbounded nesting_depth growth, part 2.
* gettext-tools/src/x-perl.c: Return from extract_balanced when a subroutine's
definition terminates.
(extract_balanced): Test whether the first token is 'sub'. If so, don't use
the usual symbol parsing and return when a token_type_lbrace was seen.
Test cases:
==========================================
sub import {
}
==========================================
sub import {
if (!$module_loaded) {
Texinfo::XSLoader::override("", "");
Texinfo::XSLoader::override("", "");
$module_loaded = 1;
}
goto &Exporter::import;
}
==========================================
Bruno Haible [Mon, 18 Sep 2023 14:18:23 +0000 (16:18 +0200)]
xgettext: Perl: Avoid unbounded nesting_depth growth, part 1.
* gettext-tools/src/x-perl.c: Return from extract_balanced when a semicolon
outside parentheses is seen.
(extract_balanced): Add parameters semicolon_delim, eat_semicolon_delim.
All callers changed.
Test case:
=================
use strict;
=================
Bruno Haible [Sun, 17 Sep 2023 19:11:09 +0000 (21:11 +0200)]
build: Fix "make install" failure on Android.
This patch fixes two problems with "make install" on Android:
1) On this platform, libtool is configured to relink libraries during
"make install".
This leads to a problem during the installation of libgettextsrc: The relink
command that libtool emits has the form
The option -lgettextlib resolves to $(libdir)/libgettextlib.a, not to
$(libdir)/libgettextlib-@VERSION@.so.
Thus the linker attempts to include many object files from libgettextlib.a
into libgettextsrc-@VERSION@.soT, but some of these reference global variables
in a non-PIC way, and the linker thus complains
ld.lld: error: relocation R_ARM_REL32 cannot be used against symbol 'program_name'; recompile with -fPIC
2) The installed executables don't have a RUNPATH property that points to the
directory that contains the shared libraries. Thus these executables don't run.
Reported at <https://savannah.gnu.org/patch/index.php?10393>.
* m4/libtool.m4: On Android, fix library_names_spec and
hardcode_libdir_flag_spec.