Wolfgang Jeltsch pushed to branch wip/jeltsch/querying-newline-modes at Glasgow Haskell Compiler / GHC
Commits:
-
9c8a9fda
by Wolfgang Jeltsch at 2025-12-22T15:05:53+02:00
8 changed files:
- libraries/base/changelog.md
- libraries/base/src/System/IO.hs
- libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs
- libraries/ghc-internal/src/GHC/Internal/System/IO.hs
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
Changes:
| 1 | 1 | # Changelog for [`base` package](http://hackage.haskell.org/package/base)
|
| 2 | 2 | |
| 3 | 3 | ## 4.23.0.0 *TBA*
|
| 4 | + * Add `System.IO.hGetNewlineMode`. ([CLC proposal #370](https://github.com/haskell/core-libraries-committee/issues/370))
|
|
| 4 | 5 | * Add `{-# WARNING in "x-partial" #-}` to `Data.List.{init,last}`.
|
| 5 | 6 | Use `{-# OPTIONS_GHC -Wno-x-partial #-}` to disable it.
|
| 6 | 7 | ([CLC proposal #87](https://github.com/haskell/core-libraries-committee/issues/292))
|
| ... | ... | @@ -175,6 +175,7 @@ module System.IO |
| 175 | 175 | -- Binary-mode 'Handle's do no newline translation at all.
|
| 176 | 176 | |
| 177 | 177 | hSetNewlineMode,
|
| 178 | + hGetNewlineMode,
|
|
| 178 | 179 | Newline(..),
|
| 179 | 180 | nativeNewline,
|
| 180 | 181 | NewlineMode(..),
|
| ... | ... | @@ -40,7 +40,7 @@ module GHC.Internal.IO.Handle ( |
| 40 | 40 | hIsOpen, hIsClosed, hIsReadable, hIsWritable, hGetBuffering, hIsSeekable,
|
| 41 | 41 | hSetEcho, hGetEcho, hIsTerminalDevice,
|
| 42 | 42 | |
| 43 | - hSetNewlineMode, Newline(..), NewlineMode(..), nativeNewline,
|
|
| 43 | + hSetNewlineMode, hGetNewlineMode, Newline(..), NewlineMode(..), nativeNewline,
|
|
| 44 | 44 | noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
|
| 45 | 45 | |
| 46 | 46 | hShow,
|
| ... | ... | @@ -238,7 +238,7 @@ hSetBuffering handle mode = |
| 238 | 238 | return Handle__{ haBufferMode = mode,.. }
|
| 239 | 239 | |
| 240 | 240 | -- -----------------------------------------------------------------------------
|
| 241 | --- hSetEncoding
|
|
| 241 | +-- Setting and getting the text encoding
|
|
| 242 | 242 | |
| 243 | 243 | -- | The action 'hSetEncoding' @hdl@ @encoding@ changes the text encoding
|
| 244 | 244 | -- for the handle @hdl@ to @encoding@. The default encoding when a 'Handle' is
|
| ... | ... | @@ -624,16 +624,24 @@ hSetBinaryMode handle bin = |
| 624 | 624 | haOutputNL = outputNL nl, .. }
|
| 625 | 625 | |
| 626 | 626 | -- -----------------------------------------------------------------------------
|
| 627 | --- hSetNewlineMode
|
|
| 627 | +-- Setting and getting the newline mode
|
|
| 628 | 628 | |
| 629 | --- | Set the 'NewlineMode' on the specified 'Handle'. All buffered
|
|
| 629 | +-- | Set the 'NewlineMode' for the specified 'Handle'. All buffered
|
|
| 630 | 630 | -- data is flushed first.
|
| 631 | 631 | hSetNewlineMode :: Handle -> NewlineMode -> IO ()
|
| 632 | -hSetNewlineMode handle NewlineMode{ inputNL=i, outputNL=o } =
|
|
| 632 | +hSetNewlineMode handle NewlineMode{..} =
|
|
| 633 | 633 | withAllHandles__ "hSetNewlineMode" handle $ \h_@Handle__{} ->
|
| 634 | 634 | do
|
| 635 | 635 | flushBuffer h_
|
| 636 | - return h_{ haInputNL=i, haOutputNL=o }
|
|
| 636 | + return h_{ haInputNL = inputNL, haOutputNL = outputNL }
|
|
| 637 | + |
|
| 638 | +-- | Return the current 'NewlineMode' for the specified 'Handle'.
|
|
| 639 | +--
|
|
| 640 | +-- @since 4.23.0.0
|
|
| 641 | +hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 642 | +hGetNewlineMode hdl =
|
|
| 643 | + withHandle_ "hGetNewlineMode" hdl $ \h_@Handle__{..} ->
|
|
| 644 | + return NewlineMode{ inputNL = haInputNL, outputNL = haOutputNL }
|
|
| 637 | 645 | |
| 638 | 646 | -- -----------------------------------------------------------------------------
|
| 639 | 647 | -- Duplicating a Handle
|
| ... | ... | @@ -214,6 +214,7 @@ module GHC.Internal.System.IO ( |
| 214 | 214 | -- Binary-mode 'Handle's do no newline translation at all.
|
| 215 | 215 | --
|
| 216 | 216 | hSetNewlineMode,
|
| 217 | + hGetNewlineMode,
|
|
| 217 | 218 | Newline(..), nativeNewline,
|
| 218 | 219 | NewlineMode(..),
|
| 219 | 220 | noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
|
| ... | ... | @@ -10263,6 +10263,7 @@ module System.IO where |
| 10263 | 10263 | hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
|
| 10264 | 10264 | hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
|
| 10265 | 10265 | hGetLine :: Handle -> IO GHC.Internal.Base.String
|
| 10266 | + hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 10266 | 10267 | hGetPosn :: Handle -> IO HandlePosn
|
| 10267 | 10268 | hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
|
| 10268 | 10269 | hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -13309,6 +13309,7 @@ module System.IO where |
| 13309 | 13309 | hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
|
| 13310 | 13310 | hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
|
| 13311 | 13311 | hGetLine :: Handle -> IO GHC.Internal.Base.String
|
| 13312 | + hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 13312 | 13313 | hGetPosn :: Handle -> IO HandlePosn
|
| 13313 | 13314 | hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
|
| 13314 | 13315 | hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -10543,6 +10543,7 @@ module System.IO where |
| 10543 | 10543 | hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
|
| 10544 | 10544 | hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
|
| 10545 | 10545 | hGetLine :: Handle -> IO GHC.Internal.Base.String
|
| 10546 | + hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 10546 | 10547 | hGetPosn :: Handle -> IO HandlePosn
|
| 10547 | 10548 | hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
|
| 10548 | 10549 | hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
|
| ... | ... | @@ -10263,6 +10263,7 @@ module System.IO where |
| 10263 | 10263 | hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
|
| 10264 | 10264 | hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
|
| 10265 | 10265 | hGetLine :: Handle -> IO GHC.Internal.Base.String
|
| 10266 | + hGetNewlineMode :: Handle -> IO NewlineMode
|
|
| 10266 | 10267 | hGetPosn :: Handle -> IO HandlePosn
|
| 10267 | 10268 | hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
|
| 10268 | 10269 | hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
|