[MLton-commit] r5927

Matthew Fluet fluet at mlton.org
Wed Aug 22 07:12:37 PDT 2007


Recent versions Cygwin don't work with the 'pure win32' implementation of cwait
----------------------------------------------------------------------

U   mlton/trunk/lib/mlton-stubs/mlton.sml
U   mlton/trunk/runtime/platform/cygwin.c

----------------------------------------------------------------------

Modified: mlton/trunk/lib/mlton-stubs/mlton.sml
===================================================================
--- mlton/trunk/lib/mlton-stubs/mlton.sml	2007-08-22 13:25:59 UTC (rev 5926)
+++ mlton/trunk/lib/mlton-stubs/mlton.sml	2007-08-22 14:12:37 UTC (rev 5927)
@@ -223,7 +223,7 @@
                    | OpenBSD
                    | Solaris
 
-                  val host: t = Linux
+                  val host: t = Cygwin
 
                   val all = [(AIX, "AIX"),
                              (Cygwin, "Cygwin"),

Modified: mlton/trunk/runtime/platform/cygwin.c
===================================================================
--- mlton/trunk/runtime/platform/cygwin.c	2007-08-22 13:25:59 UTC (rev 5926)
+++ mlton/trunk/runtime/platform/cygwin.c	2007-08-22 14:12:37 UTC (rev 5927)
@@ -118,37 +118,51 @@
 /*                      Process                      */
 /* ------------------------------------------------- */
 
+C_Errno_t(C_PId_t) MLton_Process_cwait (C_PId_t pid, Ref(C_Status_t) status) {
+  HANDLE h;
+
+  h = (HANDLE)pid;
+  /* -1 on error, the casts here are due to bad types on both sides */
+  return cwait ((int*)status, (pid_t)h, 0);
+}
+
+/* 20070822, fluet: The following 'pure win32' implementation of cwait
+ * no longer works on recent Cygwin versions.  It always takes the
+ * {errno = ECHILD; return -1} branch, even when the child process
+ * exists.
+ */
+
 /* Cygwin replaces cwait with a call to waitpid.
  * waitpid only works when the process was created by cygwin and there
  * is a secret magical pipe for sending signals and exit statuses over.
  * Screw that. We implement our own cwait using pure win32.
  */
-C_Errno_t(C_PId_t) MLton_Process_cwait(C_PId_t pid, Ref(C_Status_t) status) {
-        HANDLE h;
+/* C_Errno_t(C_PId_t) MLton_Process_cwait(C_PId_t pid, Ref(C_Status_t) status) { */
+/*         HANDLE h; */
 
-        h = (HANDLE)pid;
-        /* This all works on Win95+ */
-        while (1) {
-                /* Using an open handle we can get the exit status */
-                unless (GetExitCodeProcess (h, (DWORD*)status)) {
-                        /* An error probably means the child does not exist */
-                        errno = ECHILD;
-                        return -1;
-                }
-                /* Thank you windows API.
-                 * I hope no process ever exits with STILL_ACTIVE.
-                 * At least most other windows programs have this bug too.
-                 */
-                if (*(DWORD*)status != STILL_ACTIVE) /* 259 */
-                        break;
-                /* Wait for h to change state for up to one second.
-                 * We don't wait longer b/c there is a race condition
-                 * between checking the exit status and calling this method.
-                 * By only waiting 1s, no infinite loop can result.
-                 */
-                WaitForSingleObject (h, 1000);
-        }
-        /* Cleanup the process handle -- don't call this method again */
-        CloseHandle (h);
-        return pid;
-}
+/*         h = (HANDLE)pid; */
+/*         /\* This all works on Win95+ *\/ */
+/*         while (1) { */
+/*                 /\* Using an open handle we can get the exit status *\/ */
+/*                 unless (GetExitCodeProcess (h, (DWORD*)status)) { */
+/*                         /\* An error probably means the child does not exist *\/ */
+/*                         errno = ECHILD; */
+/*                         return -1; */
+/*                 } */
+/*                 /\* Thank you windows API. */
+/*                  * I hope no process ever exits with STILL_ACTIVE. */
+/*                  * At least most other windows programs have this bug too. */
+/*                  *\/ */
+/*                 if (*(DWORD*)status != STILL_ACTIVE) /\* 259 *\/ */
+/*                         break; */
+/*                 /\* Wait for h to change state for up to one second. */
+/*                  * We don't wait longer b/c there is a race condition */
+/*                  * between checking the exit status and calling this method. */
+/*                  * By only waiting 1s, no infinite loop can result. */
+/*                  *\/ */
+/*                 WaitForSingleObject (h, 1000); */
+/*         } */
+/*         /\* Cleanup the process handle -- don't call this method again *\/ */
+/*         CloseHandle (h); */
+/*         return pid; */
+/* } */




More information about the MLton-commit mailing list