Thanks Bruno! On Tue, 30 Apr 2024, 7:19 pm Bruno Haible, <br...@clisp.org> wrote:
> [CCing bug-gnulib] > > Hi, > > Paul Harris wrote: > > During ./configure, the "intl" configure step tests this condition: > > checking whether printf supports the 'n' directive... > > > > This fails on MSVC, which is fine on Release builds. > > > > However, in Debug builds, a GUI Dialog box pops up telling the user about > > an assert failure, and would the user like to Abort,Retry,Ignore. > > > > This blocks the configuration until the user manually presses a button. > > > > In gettext-runtime/intl/configure (in the tarball release), > > line 29702 has a call to _set_invalid_parameter_handler() > > This almost does the job, but not quite. > > adding the line: _CrtSetReportMode(_CRT_ASSERT, 0); > > changes the behaviour to fail without the dialog box. > > > > There are other places in the tarball where > > _set_invalid_parameter_handler() is called, and this line could be added > in > > all of those places to be sure, but my tests show it is enough to add it > to > > just this one place, > > > > here is a patch: > > > > diff -ru gettext-runtime/intl/configure gettext-runtime/intl/configure > > --- gettext-runtime/intl/configure 2023-06-17 19:53:51.000000000 +0800 > > +++ gettext-runtime/intl/configure 2024-04-29 10:52:53.723390500 +0800 > > @@ -29700,6 +29700,7 @@ > > int count = -1; > > #ifdef _MSC_VER > > _set_invalid_parameter_handler (invalid_parameter_handler); > > + _CrtSetReportMode(_CRT_ASSERT, 0); > > #endif > > /* Copy the format string. Some systems (glibc with > _FORTIFY_SOURCE=2) > > support %n in format strings in read-only memory but not in > writable > > > > > > These files appear to be generated for the benefit of the tarball, and > > aren't found in the git at all, so I wasn't sure how to patch anywhere > else. > > Perhaps this belongs in m4 or coreutils or autoconf ? I'm not sure. > > Thanks for the report and suggestion. The code comes from Gnulib; therefore > I'm fixing it in Gnulib. > > The use of _CrtSetReportMode requires a #include <crtdbg.h>, says the > Microsoft > documentation. Therefore I'm adding that too. (Older mingw versions don't > have > <crtdbg.h>, but since we need the workaround only for MSVC, not for mingw, > this is not a problem.) > > > 2024-04-30 Bruno Haible <br...@clisp.org> > > *printf: Avoid a dialog during 'configure' with MSVC in debug mode. > Suggested by Paul Harris <harris...@gmail.com> in > < > https://lists.gnu.org/archive/html/bug-gettext/2024-04/msg00005.html>. > * m4/printf.m4 (gl_PRINTF_DIRECTIVE_N): In the test program, > include > <crtdbg.h> and disable the MSVC reporting for assertion failures. > > diff --git a/m4/printf.m4 b/m4/printf.m4 > index 0cb14d6f00..220f37cb5e 100644 > --- a/m4/printf.m4 > +++ b/m4/printf.m4 > @@ -1,5 +1,5 @@ > # printf.m4 > -# serial 91 > +# serial 92 > dnl Copyright (C) 2003, 2007-2024 Free Software Foundation, Inc. > dnl This file is free software; the Free Software Foundation > dnl gives unlimited permission to copy and/or distribute it, > @@ -896,6 +896,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N] > #include <stdlib.h> > #include <string.h> > #ifdef _MSC_VER > +#include <crtdbg.h> > #include <inttypes.h> > /* See page about "Parameter Validation" on msdn.microsoft.com. > < > https://docs.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation > > > @@ -922,6 +923,9 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N] > int count = -1; > #ifdef _MSC_VER > _set_invalid_parameter_handler (invalid_parameter_handler); > + /* Also avoid an Abort/Retry/Ignore dialog in debug builds. > + < > https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode> > */ > + _CrtSetReportMode (_CRT_ASSERT, 0); > #endif > signal (SIGABRT, abort_handler); > /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) > > > >