bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gettext@gnu.org, bug-gnulib@gnu.org
Cc: Paul Harris <harris.pc@gmail.com>
Subject: Re: ./configure with MSVC + Debug blocks with dialog box (fixed with patch!)
Date: Tue, 30 Apr 2024 13:19:42 +0200	[thread overview]
Message-ID: <9839652.G0QQBjFxQf@nimes> (raw)
In-Reply-To: <CAMSUDdY=ftxyqj3LO-bDJwMR81H4joWqU+BRq7Y1DvumkSC0Hw@mail.gmail.com>

[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  <bruno@clisp.org>

	*printf: Avoid a dialog during 'configure' with MSVC in debug mode.
	Suggested by Paul Harris <harris.pc@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)





       reply	other threads:[~2024-04-30 11:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAMSUDdY=ftxyqj3LO-bDJwMR81H4joWqU+BRq7Y1DvumkSC0Hw@mail.gmail.com>
2024-04-30 11:19 ` Bruno Haible [this message]
2024-04-30 12:40   ` ./configure with MSVC + Debug blocks with dialog box (fixed with patch!) Paul Harris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9839652.G0QQBjFxQf@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gettext@gnu.org \
    --cc=bug-gnulib@gnu.org \
    --cc=harris.pc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).