Skip to content

Commit

Permalink
Add a comment about non-atomic B.hPutStrLn
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Jun 22, 2024
1 parent e1068f1 commit fd62de7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Data/Text/Internal/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,16 @@ hPutStream h str = hPutStreamOrUtf8 h str Nothing
-- | Write a string to a handle.
hPutStr :: Handle -> Text -> IO ()
hPutStr h t = hPutStreamOrUtf8 h (stream t) (Just putUtf8)
where putUtf8 = B.hPutStr h (encodeUtf8 t)
where
putUtf8 = B.hPutStr h (encodeUtf8 t)

-- | Write a string to a handle, followed by a newline.
hPutStrLn :: Handle -> Text -> IO ()
hPutStrLn h t = hPutStreamOrUtf8 h (streamLn t) (Just putUtf8)
where putUtf8 = hPutBuilder h (encodeUtf8Builder t <> charUtf8 '\n')
where
-- Not using B.hPutStrLn because it's not necessarily atomic:
-- https://github.com/haskell/bytestring/issues/200
putUtf8 = hPutBuilder h (encodeUtf8Builder t <> charUtf8 '\n')

-- | 'hPutStream' with an optional special case when the output encoding is
-- UTF-8 and without newline conversion.
Expand Down

0 comments on commit fd62de7

Please sign in to comment.