[commit: process] master: Small code cleanup (04dfeed)

Ian Lynagh igloo at earth.li
Sat Apr 27 22:53:06 CEST 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/process

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/04dfeed25e0476c2dddc7afff1156f0b1a0a9f45

>---------------------------------------------------------------

commit 04dfeed25e0476c2dddc7afff1156f0b1a0a9f45
Author: Ian Lynagh <ian at well-typed.com>
Date:   Sat Apr 27 20:30:17 2013 +0100

    Small code cleanup

>---------------------------------------------------------------

 System/Process.hs           |   24 ++++++++++++------------
 System/Process/Internals.hs |   14 +++++++-------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/System/Process.hs b/System/Process.hs
index 0557284..8399ad4 100644
--- a/System/Process.hs
+++ b/System/Process.hs
@@ -337,7 +337,7 @@ waitForProcess
   :: ProcessHandle
   -> IO ExitCode
 waitForProcess ph = do
-  p_ <- withProcessHandle ph $ \p_ -> return (p_,p_)
+  p_ <- modifyProcessHandle ph $ \p_ -> return (p_,p_)
   case p_ of
     ClosedHandle e -> return e
     OpenHandle h  -> do
@@ -346,7 +346,7 @@ waitForProcess ph = do
         -- thread could close the handle or call waitForProcess)
         alloca $ \pret -> do
           throwErrnoIfMinus1Retry_ "waitForProcess" (c_waitForProcess h pret)
-          withProcessHandle ph $ \p_' ->
+          modifyProcessHandle ph $ \p_' ->
             case p_' of
               ClosedHandle e -> return (p_',e)
               OpenHandle ph' -> do
@@ -608,12 +608,12 @@ showCommandForUser cmd args = unwords (map translate (cmd : args))
 
 terminateProcess :: ProcessHandle -> IO ()
 terminateProcess ph = do
-  withProcessHandle_ ph $ \p_ ->
+  withProcessHandle ph $ \p_ ->
     case p_ of
-      ClosedHandle _ -> return p_
+      ClosedHandle _ -> return ()
       OpenHandle h -> do
         throwErrnoIfMinus1Retry_ "terminateProcess" $ c_terminateProcess h
-        return p_
+        return ()
         -- does not close the handle, we might want to try terminating it
         -- again, or get its exit code.
 
@@ -632,17 +632,17 @@ interruptProcessGroupOf
     -> IO ()
 interruptProcessGroupOf ph = do
 #if mingw32_HOST_OS
-    withProcessHandle_ ph $ \p_ -> do
+    withProcessHandle ph $ \p_ -> do
         case p_ of
-            ClosedHandle _ -> return p_
+            ClosedHandle _ -> return ()
             OpenHandle h -> do
                 pid <- getProcessId h
                 generateConsoleCtrlEvent cTRL_BREAK_EVENT pid
-                return p_
+                return ()
 #else
-    withProcessHandle_ ph $ \p_ -> do
+    withProcessHandle ph $ \p_ -> do
         case p_ of
-            ClosedHandle _ -> return p_
+            ClosedHandle _ -> return ()
             OpenHandle h -> do
 #if MIN_VERSION_unix(2,5,0)
                 -- getProcessGroupIDOf was added in unix-2.5.0.0
@@ -651,7 +651,7 @@ interruptProcessGroupOf ph = do
 #else
                 signalProcessGroup sigINT h
 #endif
-                return p_
+                return ()
 #endif
 
 -- ----------------------------------------------------------------------------
@@ -668,7 +668,7 @@ when the process died as the result of a signal.
 
 getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
 getProcessExitCode ph = do
-  withProcessHandle ph $ \p_ ->
+  modifyProcessHandle ph $ \p_ ->
     case p_ of
       ClosedHandle e -> return (p_, Just e)
       OpenHandle h ->
diff --git a/System/Process/Internals.hs b/System/Process/Internals.hs
index f94dc52..2d605c1 100644
--- a/System/Process/Internals.hs
+++ b/System/Process/Internals.hs
@@ -23,7 +23,7 @@ module System.Process.Internals (
 #ifndef __HUGS__
         ProcessHandle(..), ProcessHandle__(..), 
         PHANDLE, closePHANDLE, mkProcessHandle, 
-        withProcessHandle, withProcessHandle_,
+        modifyProcessHandle, withProcessHandle,
 #ifdef __GLASGOW_HASKELL__
         CreateProcess(..),
         CmdSpec(..), StdStream(..),
@@ -107,17 +107,17 @@ import System.FilePath
 data ProcessHandle__ = OpenHandle PHANDLE | ClosedHandle ExitCode
 newtype ProcessHandle = ProcessHandle (MVar ProcessHandle__)
 
-withProcessHandle
+modifyProcessHandle
         :: ProcessHandle 
         -> (ProcessHandle__ -> IO (ProcessHandle__, a))
         -> IO a
-withProcessHandle (ProcessHandle m) io = modifyMVar m io
+modifyProcessHandle (ProcessHandle m) io = modifyMVar m io
 
-withProcessHandle_
+withProcessHandle
         :: ProcessHandle 
-        -> (ProcessHandle__ -> IO ProcessHandle__)
-        -> IO ()
-withProcessHandle_ (ProcessHandle m) io = modifyMVar_ m io
+        -> (ProcessHandle__ -> IO a)
+        -> IO a
+withProcessHandle (ProcessHandle m) io = withMVar m io
 
 #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
 





More information about the ghc-commits mailing list