[commit: ghc] master: fdReady: Use C99 bools / CBool in signature (430d1f6)
git at git.haskell.org
git at git.haskell.org
Mon Dec 11 19:27:04 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/430d1f6a6ea37dd53887391c060ce53be792336f/ghc
>---------------------------------------------------------------
commit 430d1f6a6ea37dd53887391c060ce53be792336f
Author: Niklas Hambüchen <mail at nh2.me>
Date: Mon Dec 11 13:06:33 2017 -0500
fdReady: Use C99 bools / CBool in signature
Reviewers: bgamari, Phyx, austin, hvr, simonmar
Reviewed By: bgamari
Subscribers: syd, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D4041
>---------------------------------------------------------------
430d1f6a6ea37dd53887391c060ce53be792336f
libraries/base/Control/Concurrent.hs | 14 +++++++-------
libraries/base/GHC/IO/FD.hs | 4 ++--
libraries/base/cbits/inputReady.c | 2 +-
libraries/base/include/HsBase.h | 3 ++-
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/libraries/base/Control/Concurrent.hs b/libraries/base/Control/Concurrent.hs
index 0946399..bd222e2 100644
--- a/libraries/base/Control/Concurrent.hs
+++ b/libraries/base/Control/Concurrent.hs
@@ -407,7 +407,7 @@ threadWaitRead fd
-- fdReady does the right thing, but we have to call it in a
-- separate thread, otherwise threadWaitRead won't be interruptible,
-- and this only works with -threaded.
- | threaded = withThread (waitFd fd 0)
+ | threaded = withThread (waitFd fd False)
| otherwise = case fd of
0 -> do _ <- hWaitForInput stdin (-1)
return ()
@@ -428,7 +428,7 @@ threadWaitRead fd
threadWaitWrite :: Fd -> IO ()
threadWaitWrite fd
#if defined(mingw32_HOST_OS)
- | threaded = withThread (waitFd fd 1)
+ | threaded = withThread (waitFd fd True)
| otherwise = errorWithoutStackTrace "threadWaitWrite requires -threaded on Windows"
#else
= GHC.Conc.threadWaitWrite fd
@@ -444,7 +444,7 @@ threadWaitReadSTM :: Fd -> IO (STM (), IO ())
threadWaitReadSTM fd
#if defined(mingw32_HOST_OS)
| threaded = do v <- newTVarIO Nothing
- mask_ $ void $ forkIO $ do result <- try (waitFd fd 0)
+ mask_ $ void $ forkIO $ do result <- try (waitFd fd False)
atomically (writeTVar v $ Just result)
let waitAction = do result <- readTVar v
case result of
@@ -468,7 +468,7 @@ threadWaitWriteSTM :: Fd -> IO (STM (), IO ())
threadWaitWriteSTM fd
#if defined(mingw32_HOST_OS)
| threaded = do v <- newTVarIO Nothing
- mask_ $ void $ forkIO $ do result <- try (waitFd fd 1)
+ mask_ $ void $ forkIO $ do result <- try (waitFd fd True)
atomically (writeTVar v $ Just result)
let waitAction = do result <- readTVar v
case result of
@@ -494,13 +494,13 @@ withThread io = do
Right a -> return a
Left e -> throwIO (e :: IOException)
-waitFd :: Fd -> CInt -> IO ()
+waitFd :: Fd -> Bool -> IO ()
waitFd fd write = do
throwErrnoIfMinus1_ "fdReady" $
- fdReady (fromIntegral fd) write (-1) 0
+ fdReady (fromIntegral fd) (if write then 1 else 0) (-1) 0
foreign import ccall safe "fdReady"
- fdReady :: CInt -> CInt -> Int64 -> CInt -> IO CInt
+ fdReady :: CInt -> CBool -> Int64 -> CBool -> IO CInt
#endif
-- ---------------------------------------------------------------------------
diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs
index 4a4f063..bb188a9 100644
--- a/libraries/base/GHC/IO/FD.hs
+++ b/libraries/base/GHC/IO/FD.hs
@@ -401,7 +401,7 @@ ready fd write msecs = do
return (toEnum (fromIntegral r))
foreign import ccall safe "fdReady"
- fdReady :: CInt -> CInt -> Int64 -> CInt -> IO CInt
+ fdReady :: CInt -> CBool -> Int64 -> CBool -> IO CInt
-- ---------------------------------------------------------------------------
-- Terminal-related stuff
@@ -562,7 +562,7 @@ isNonBlocking :: FD -> Bool
isNonBlocking fd = fdIsNonBlocking fd /= 0
foreign import ccall unsafe "fdReady"
- unsafe_fdReady :: CInt -> CInt -> Int64 -> CInt -> IO CInt
+ unsafe_fdReady :: CInt -> CBool -> Int64 -> CBool -> IO CInt
#else /* mingw32_HOST_OS.... */
diff --git a/libraries/base/cbits/inputReady.c b/libraries/base/cbits/inputReady.c
index a3024bf..9b1bb9e 100644
--- a/libraries/base/cbits/inputReady.c
+++ b/libraries/base/cbits/inputReady.c
@@ -134,7 +134,7 @@ compute_WaitForSingleObject_timeout(bool infinite, Time remaining)
* On error, sets `errno`.
*/
int
-fdReady(int fd, int write, int64_t msecs, int isSock)
+fdReady(int fd, bool write, int64_t msecs, bool isSock)
{
bool infinite = msecs < 0;
diff --git a/libraries/base/include/HsBase.h b/libraries/base/include/HsBase.h
index 748e357..13640c5 100644
--- a/libraries/base/include/HsBase.h
+++ b/libraries/base/include/HsBase.h
@@ -24,6 +24,7 @@
#include "HsFFI.h"
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@@ -152,7 +153,7 @@ extern HsWord64 getMonotonicUSec(void);
#endif
/* in inputReady.c */
-extern int fdReady(int fd, int write, int64_t msecs, int isSock);
+extern int fdReady(int fd, bool write, int64_t msecs, bool isSock);
/* -----------------------------------------------------------------------------
INLINE functions.
More information about the ghc-commits
mailing list