[Git][ghc/ghc][wip/jeltsch/duplex-readability-and-writability] Correct `hIsReadable` and `hIsWritable` for duplex handles
Wolfgang Jeltsch pushed to branch wip/jeltsch/duplex-readability-and-writability at Glasgow Haskell Compiler / GHC Commits: 3e3b8f80 by Wolfgang Jeltsch at 2025-12-20T18:16:26+02:00 Correct `hIsReadable` and `hIsWritable` for duplex handles This contribution implements CLC proposal #371. It changes `hIsReadable` and `hIsWritable` such that they always throw a respective exception when encountering a closed or semi-closed handle, not just in the case of a file handle. - - - - - 1 changed file: - libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs Changes: ===================================== libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs ===================================== @@ -502,9 +502,14 @@ hIsClosed handle = -- | @'hIsReadable' hdl@ returns whether it is possible to read from the handle. hIsReadable :: Handle -> IO Bool -hIsReadable (DuplexHandle _ _ _) = return True -hIsReadable handle = - withHandle_ "hIsReadable" handle $ \ handle_ -> do +hIsReadable handle@(FileHandle _ var) + = hIsReadable' handle var +hIsReadable handle@(DuplexHandle _ readingVar _) + = hIsReadable' handle readingVar + +hIsReadable' :: Handle -> MVar Handle__ -> IO Bool +hIsReadable' handle readingVar = + withHandle_' "hIsReadable" handle readingVar $ \ handle_ -> do case haType handle_ of ClosedHandle -> ioe_closedHandle SemiClosedHandle -> ioe_semiclosedHandle @@ -512,9 +517,14 @@ hIsReadable handle = -- | @'hIsWritable' hdl@ returns whether it is possible to write to the handle. hIsWritable :: Handle -> IO Bool -hIsWritable (DuplexHandle _ _ _) = return True -hIsWritable handle = - withHandle_ "hIsWritable" handle $ \ handle_ -> do +hIsWritable handle@(FileHandle _ var) + = hIsWritable' handle var +hIsWritable handle@(DuplexHandle _ _ writingVar) + = hIsWritable' handle writingVar + +hIsWritable' :: Handle -> MVar Handle__ -> IO Bool +hIsWritable' handle writingVar = + withHandle_' "hIsWritable" handle writingVar $ \ handle_ -> do case haType handle_ of ClosedHandle -> ioe_closedHandle SemiClosedHandle -> ioe_semiclosedHandle View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3e3b8f80957eed64cabded0e0ab0190d... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3e3b8f80957eed64cabded0e0ab0190d... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Wolfgang Jeltsch (@jeltsch)