From 655ed9d83889bbb61d4b96755a2bd676622064c8 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 24 Jul 2019 14:04:56 +0900 Subject: w32: Fix HANDLE to internal fd conversion. * src/spawn-w32.c (handle_to_fd): Use intptr_t type. -- See the section of _open_osfhandle in C Run-Time Library Reference. Signed-off-by: NIIBE Yutaka --- src/spawn-w32.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/spawn-w32.c b/src/spawn-w32.c index 91f9ac4..12ebe40 100644 --- a/src/spawn-w32.c +++ b/src/spawn-w32.c @@ -54,14 +54,29 @@ #undef X_OK #define X_OK F_OK -/* We assume that a HANDLE can be represented by an int which should - * be true for all i386 systems (HANDLE is defined as void *) and - * these are the only systems for which Windows is available. Further - * we assume that -1 denotes an invalid handle. - * FIXME: With Windows 64 this is no longer true. +/* For HANDLE and the internal file descriptor (fd) of this module: + * HANDLE can be represented by an intptr_t which should be true for + * all systems (HANDLE is defined as void *). Further, we assume that + * -1 denotes an invalid handle. + * + * Note that a C run-time file descriptor (the exposed one to API) is + * always represented by an int. */ #define fd_to_handle(a) ((HANDLE)(a)) -#define handle_to_fd(a) ((int)(a)) +#define handle_to_fd(a) ((intptr_t)(a)) + +/* For pid_t and HANDLE: + + * We assume that a HANDLE can be represented by an int which should + * be true for all i386 systems. + * + * On 64-bit machine, it is no longer true, as a type, however, as + * long as the range of the value in the type HANDLE can be + * represented by an int, it works. + * + * FIXME: Breaking ABI for pid_t will be needed when the value won't + * fit within 32-bit range on 64-bit machine. + */ #define pid_to_handle(a) ((HANDLE)(a)) #define handle_to_pid(a) ((int)(a)) -- cgit v1.2.3