On 64-bit Windows, pid_t needs to be 64-bit large, i.e. intptr_t or 'long long' or '__int64'.
This is because the return type of _spawnv* (when invoked with _P_NOWAIT) and the argument of the _cwait function are 'intptr_t' (see [1][2]: "The return value from an asynchronous _spawnvp or _wspawnvp (_P_NOWAIT or _P_NOWAITO specified for mode) is the process handle." On mingw, this is already the case. But on MSVC (and MSVC/clang), the 'pid_t' type is nowhere defined. In this case, gnulib defines it through config.h. [1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnvp-wspawnvp [2] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/cwait 2020-08-23 Bruno Haible <[email protected]> tests: Don't assume that pid_t fits in an 'int'. * tests/test-nonblocking-pipe-main.c (main): Use type 'pid_t' instead of 'int'. * tests/test-nonblocking-socket-main.c (main): Likewise. sys_types: Fix definition of pid_t on 64-bit MSVC. * m4/pid_t.m4: New file. * modules/sys_types (Files): Add it. * modules/dirent (Files): Likewise. * modules/fcntl-h (Files): Likewise. * modules/sched (Files): Likewise. * modules/signal-h (Files): Likewise. * modules/spawn (Files): Likewise. * modules/sys_stat (Files): Likewise. * modules/sys_wait (Files): Likewise. * modules/termios (Files): Likewise. * modules/unistd (Files): Likewise.
>From efe32f6a916b6addcfe60d2283cef4cebc6177ff Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Mon, 24 Aug 2020 01:19:18 +0200 Subject: [PATCH 1/2] sys_types: Fix definition of pid_t on 64-bit MSVC. * m4/pid_t.m4: New file. * modules/sys_types (Files): Add it. * modules/dirent (Files): Likewise. * modules/fcntl-h (Files): Likewise. * modules/sched (Files): Likewise. * modules/signal-h (Files): Likewise. * modules/spawn (Files): Likewise. * modules/sys_stat (Files): Likewise. * modules/sys_wait (Files): Likewise. * modules/termios (Files): Likewise. * modules/unistd (Files): Likewise. --- ChangeLog | 15 +++++++++++++++ m4/pid_t.m4 | 33 +++++++++++++++++++++++++++++++++ modules/dirent | 1 + modules/fcntl-h | 1 + modules/sched | 1 + modules/signal-h | 1 + modules/spawn | 1 + modules/sys_stat | 1 + modules/sys_types | 1 + modules/sys_wait | 1 + modules/termios | 1 + modules/unistd | 1 + 12 files changed, 58 insertions(+) create mode 100644 m4/pid_t.m4 diff --git a/ChangeLog b/ChangeLog index e54c89f..9c2dcdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2020-08-23 Bruno Haible <[email protected]> + sys_types: Fix definition of pid_t on 64-bit MSVC. + * m4/pid_t.m4: New file. + * modules/sys_types (Files): Add it. + * modules/dirent (Files): Likewise. + * modules/fcntl-h (Files): Likewise. + * modules/sched (Files): Likewise. + * modules/signal-h (Files): Likewise. + * modules/spawn (Files): Likewise. + * modules/sys_stat (Files): Likewise. + * modules/sys_wait (Files): Likewise. + * modules/termios (Files): Likewise. + * modules/unistd (Files): Likewise. + +2020-08-23 Bruno Haible <[email protected]> + inttypes: Fix {PRI,SCN}*PTR on 32-bit native Windows (regr. 2020-07-21). * m4/inttypes.m4 (gl_INTTYPES_PRI_SCN): Fix syntax error in test program. diff --git a/m4/pid_t.m4 b/m4/pid_t.m4 new file mode 100644 index 0000000..321082d --- /dev/null +++ b/m4/pid_t.m4 @@ -0,0 +1,33 @@ +# pid_t.m4 serial 1 +dnl Copyright (C) 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Define pid_t if the headers don't define it. +AC_DEFUN([AC_TYPE_PID_T], +[ + AC_CHECK_TYPE([pid_t], + [], + [dnl On 64-bit native Windows, define it to the equivalent of 'intptr_t' + dnl (= 'long long' = '__int64'), because that is the return type + dnl of the _spawnv* functions + dnl <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnvp-wspawnvp> + dnl and the argument type of the _cwait function + dnl <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/cwait>. + dnl Otherwise (on 32-bit Windows and on old Unix platforms), define it + dnl to 'int'. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ + #if defined _WIN64 && !defined __CYGWIN__ + LLP64 + #endif + ]]) + ], + [gl_pid_type='int'], + [gl_pid_type='__int64']) + AC_DEFINE_UNQUOTED([pid_t], [$gl_pid_type], + [Define as a signed integer type capable of holding a process identifier.]) + ], + [AC_INCLUDES_DEFAULT]) +]) diff --git a/modules/dirent b/modules/dirent index 6f615b4..08a6326 100644 --- a/modules/dirent +++ b/modules/dirent @@ -5,6 +5,7 @@ Files: lib/dirent.in.h m4/dirent_h.m4 m4/unistd_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/fcntl-h b/modules/fcntl-h index ff74dec..2ef0106 100644 --- a/modules/fcntl-h +++ b/modules/fcntl-h @@ -5,6 +5,7 @@ Files: lib/fcntl.in.h m4/fcntl_h.m4 m4/fcntl-o.m4 +m4/pid_t.m4 Depends-on: extensions diff --git a/modules/sched b/modules/sched index 0b6bcae..572c57b 100644 --- a/modules/sched +++ b/modules/sched @@ -4,6 +4,7 @@ A <sched.h> include file. Files: lib/sched.in.h m4/sched_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/signal-h b/modules/signal-h index 810e2bf..2f38e9b 100644 --- a/modules/signal-h +++ b/modules/signal-h @@ -4,6 +4,7 @@ A GNU-like <signal.h>. Files: lib/signal.in.h m4/signal_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/spawn b/modules/spawn index 6e03294..f1b99ca 100644 --- a/modules/spawn +++ b/modules/spawn @@ -4,6 +4,7 @@ A POSIX compliant <spawn.h>. Files: lib/spawn.in.h m4/spawn_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/sys_stat b/modules/sys_stat index af276ab..42ae932 100644 --- a/modules/sys_stat +++ b/modules/sys_stat @@ -5,6 +5,7 @@ Files: lib/sys_stat.in.h m4/sys_stat_h.m4 m4/unistd_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/sys_types b/modules/sys_types index 81a11aa..c00862c 100644 --- a/modules/sys_types +++ b/modules/sys_types @@ -5,6 +5,7 @@ Files: lib/sys_types.in.h m4/sys_types_h.m4 m4/off_t.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/sys_wait b/modules/sys_wait index bedd7e1..73ce50b 100644 --- a/modules/sys_wait +++ b/modules/sys_wait @@ -4,6 +4,7 @@ A <sys/wait.h> for systems with missing declarations. Files: lib/sys_wait.in.h m4/sys_wait_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/termios b/modules/termios index 88056cc..8cb73e4 100644 --- a/modules/termios +++ b/modules/termios @@ -4,6 +4,7 @@ A <termios.h> that works around platform issues. Files: lib/termios.in.h m4/termios_h.m4 +m4/pid_t.m4 Depends-on: include_next diff --git a/modules/unistd b/modules/unistd index b14faaa..18b91c4 100644 --- a/modules/unistd +++ b/modules/unistd @@ -6,6 +6,7 @@ m4/unistd_h.m4 lib/unistd.c lib/unistd.in.h m4/off_t.m4 +m4/pid_t.m4 Depends-on: extern-inline -- 2.7.4
>From 83f2c832a760bd7e5d32e2d2ab8298f697cf3f70 Mon Sep 17 00:00:00 2001 From: Bruno Haible <[email protected]> Date: Mon, 24 Aug 2020 01:22:49 +0200 Subject: [PATCH 2/2] tests: Don't assume that pid_t fits in an 'int'. * tests/test-nonblocking-pipe-main.c (main): Use type 'pid_t' instead of 'int'. * tests/test-nonblocking-socket-main.c (main): Likewise. --- ChangeLog | 5 +++++ tests/test-nonblocking-pipe-main.c | 2 +- tests/test-nonblocking-socket-main.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c2dcdc..073f968 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-08-23 Bruno Haible <[email protected]> + tests: Don't assume that pid_t fits in an 'int'. + * tests/test-nonblocking-pipe-main.c (main): Use type 'pid_t' instead + of 'int'. + * tests/test-nonblocking-socket-main.c (main): Likewise. + sys_types: Fix definition of pid_t on 64-bit MSVC. * m4/pid_t.m4: New file. * modules/sys_types (Files): Add it. diff --git a/tests/test-nonblocking-pipe-main.c b/tests/test-nonblocking-pipe-main.c index 0e132f0..ec19be5 100644 --- a/tests/test-nonblocking-pipe-main.c +++ b/tests/test-nonblocking-pipe-main.c @@ -44,7 +44,7 @@ main (int argc, char *argv[]) const char *child_path; int test; int fd[2]; - int child; + pid_t child; int exitcode; child_path = argv[1]; diff --git a/tests/test-nonblocking-socket-main.c b/tests/test-nonblocking-socket-main.c index 500479d..d2cf50e 100644 --- a/tests/test-nonblocking-socket-main.c +++ b/tests/test-nonblocking-socket-main.c @@ -47,7 +47,7 @@ main (int argc, char *argv[]) int test; int server; int port; - int child; + pid_t child; int server_socket; int exitcode; -- 2.7.4
