]> Savannah Git Hosting - gnulib.git/commitdiff
spawn-pipe tests: Fix test failure with MSVC.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Nov 2020 22:14:56 +0000 (23:14 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Nov 2020 22:15:50 +0000 (23:15 +0100)
* 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.

ChangeLog
modules/spawn-pipe-tests
tests/test-spawn-pipe-child.c

index 5722677272229f19e5562db5c5534fcf56513b20..c702e4458a7c0d030e26028a1b5d8e9f12ed58dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
 2020-11-29  Bruno Haible  <bruno@clisp.org>
 
        execute: Add tests.
index 9a6c0bccd1d6eb5a5f2d874f3d5cda909c0c3ac7..5d1372cc0245b6622b83fae7058ed5cdf768daa8 100644 (file)
@@ -6,6 +6,8 @@ tests/macros.h
 
 Depends-on:
 close
+msvc-inval
+stdint
 
 configure.ac:
 
index 2767d1e71b52e498b5e6eec0d1b3a6e6cdb65539..176710e6317b47fce16ada8874adb551d48d58ae 100644 (file)
@@ -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;