Wolfgang Jeltsch pushed to branch wip/jeltsch/querying-newline-modes at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • libraries/base/changelog.md
    ... ... @@ -10,6 +10,7 @@
    10 10
       * Fix bug where `naturalAndNot` was incorrectly truncating results ([CLC proposal #350](github.com/haskell/core-libraries-committee/issues/350))
    
    11 11
       * Remove extra laziness from `Data.Bifunctor.Bifunctor` instances for all tuples to have the same laziness as their `Data.Functor.Functor` counterparts (i.e. they became more strict than before) ([CLC proposal #339](https://github.com/haskell/core-libraries-committee/issues/339))
    
    12 12
       * Adjust the strictness of `Data.List.iterate'` to be more reasonable: every element of the output list is forced to WHNF when the `(:)` containing it is forced. ([CLC proposal #335)](https://github.com/haskell/core-libraries-committee/issues/335)
    
    13
    +  * Add `System.IO.hGetNewlineMode` ([CLC proposal #370](https://github.com/haskell/core-libraries-committee/issues/370))
    
    13 14
     
    
    14 15
     ## 4.22.0.0 *TBA*
    
    15 16
       * Shipped with GHC 9.14.1
    

  • libraries/base/src/System/IO.hs
    ... ... @@ -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(..),
    

  • libraries/ghc-internal/src/GHC/Internal/IO/Handle.hs
    ... ... @@ -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,22 @@ 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
    +hGetNewlineMode :: Handle -> IO NewlineMode
    
    640
    +hGetNewlineMode hdl =
    
    641
    +  withHandle_ "hGetNewlineMode" hdl $ \h_@Handle__{..} ->
    
    642
    +    return NewlineMode{ inputNL = haInputNL, outputNL = haOutputNL }
    
    637 643
     
    
    638 644
     -- -----------------------------------------------------------------------------
    
    639 645
     -- Duplicating a Handle
    

  • libraries/ghc-internal/src/GHC/Internal/System/IO.hs
    ... ... @@ -213,6 +213,7 @@ module GHC.Internal.System.IO (
    213 213
         -- Binary-mode 'Handle's do no newline translation at all.
    
    214 214
         --
    
    215 215
         hSetNewlineMode,
    
    216
    +    hGetNewlineMode,
    
    216 217
         Newline(..), nativeNewline,
    
    217 218
         NewlineMode(..),
    
    218 219
         noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
    

  • testsuite/tests/interface-stability/base-exports.stdout
    ... ... @@ -10259,6 +10259,7 @@ module System.IO where
    10259 10259
       hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
    
    10260 10260
       hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
    
    10261 10261
       hGetLine :: Handle -> IO GHC.Internal.Base.String
    
    10262
    +  hGetNewlineMode :: Handle -> IO NewlineMode
    
    10262 10263
       hGetPosn :: Handle -> IO HandlePosn
    
    10263 10264
       hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
    
    10264 10265
       hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
    

  • testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
    ... ... @@ -13305,6 +13305,7 @@ module System.IO where
    13305 13305
       hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
    
    13306 13306
       hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
    
    13307 13307
       hGetLine :: Handle -> IO GHC.Internal.Base.String
    
    13308
    +  hGetNewlineMode :: Handle -> IO NewlineMode
    
    13308 13309
       hGetPosn :: Handle -> IO HandlePosn
    
    13309 13310
       hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
    
    13310 13311
       hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
    

  • testsuite/tests/interface-stability/base-exports.stdout-mingw32
    ... ... @@ -10539,6 +10539,7 @@ module System.IO where
    10539 10539
       hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
    
    10540 10540
       hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
    
    10541 10541
       hGetLine :: Handle -> IO GHC.Internal.Base.String
    
    10542
    +  hGetNewlineMode :: Handle -> IO NewlineMode
    
    10542 10543
       hGetPosn :: Handle -> IO HandlePosn
    
    10543 10544
       hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
    
    10544 10545
       hIsEOF :: Handle -> IO GHC.Internal.Types.Bool
    

  • testsuite/tests/interface-stability/base-exports.stdout-ws-32
    ... ... @@ -10259,6 +10259,7 @@ module System.IO where
    10259 10259
       hGetEcho :: Handle -> IO GHC.Internal.Types.Bool
    
    10260 10260
       hGetEncoding :: Handle -> IO (GHC.Internal.Maybe.Maybe TextEncoding)
    
    10261 10261
       hGetLine :: Handle -> IO GHC.Internal.Base.String
    
    10262
    +  hGetNewlineMode :: Handle -> IO NewlineMode
    
    10262 10263
       hGetPosn :: Handle -> IO HandlePosn
    
    10263 10264
       hIsClosed :: Handle -> IO GHC.Internal.Types.Bool
    
    10264 10265
       hIsEOF :: Handle -> IO GHC.Internal.Types.Bool