bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

spawn-pipe tests: Fix test failure with MSVC


From: Bruno Haible
Subject: spawn-pipe tests: Fix test failure with MSVC
Date: Sun, 29 Nov 2020 23:32:40 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-193-generic; KDE/5.18.0; x86_64; ; )

So far, the 'test-spawn-pipe.sh' succeeds on mingw, but fails with MSVC.
This patch fixes it.


2020-11-29  Bruno Haible  <bruno@clisp.org>

        spawn-pipe tests: Fix test failure with MSVC.
        * tests/test-spawn-pipe-child.c: Include <stdint.h>.
        (gl_msvc_invalid_parameter_handler): New function.
        (main): Set a global invalid-parameter handler.
        * modules/spawn-pipe-tests (Depends-on): Add msvc-inval, stdint.

diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests
index 9a6c0bc..5d1372c 100644
--- a/modules/spawn-pipe-tests
+++ b/modules/spawn-pipe-tests
@@ -6,6 +6,8 @@ tests/macros.h
 
 Depends-on:
 close
+msvc-inval
+stdint
 
 configure.ac:
 
diff --git a/tests/test-spawn-pipe-child.c b/tests/test-spawn-pipe-child.c
index 2767d1e..176710e 100644
--- a/tests/test-spawn-pipe-child.c
+++ b/tests/test-spawn-pipe-child.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -52,6 +53,17 @@ static FILE *myerr;
 # define fdopen _fdopen
 #endif
 
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static void __cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+}
+#endif
+
 /* Return non-zero if FD is open.  */
 static int
 is_open (int fd)
@@ -72,9 +84,6 @@ is_open (int fd)
 int
 main (int argc, char *argv[])
 {
-  char buffer[2] = { 's', 't' };
-  int fd;
-
   /* fd 2 might be closed, but fd BACKUP_STDERR_FILENO is the original
      stderr.  */
   myerr = fdopen (BACKUP_STDERR_FILENO, "w");
@@ -83,10 +92,17 @@ main (int argc, char *argv[])
 
   ASSERT (argc == 2);
 
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+  /* Avoid exceptions from within _get_osfhandle.  */
+  _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
+#endif
+
   /* Read one byte from fd 0, and write its value plus one to fd 1.
      fd 2 should be closed iff the argument is 1.  Check that no other file
      descriptors leaked.  */
 
+  char buffer[2] = { 's', 't' };
+
   ASSERT (read (STDIN_FILENO, buffer, 2) == 1);
 
   buffer[0]++;
@@ -111,6 +127,7 @@ main (int argc, char *argv[])
       ASSERT (0);
     }
 
+  int fd;
   for (fd = 3; fd < 7; fd++)
     {
       errno = 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]