From fd62de72a444e21962f3e35f4290b82fd017e21e Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Sat, 22 Jun 2024 23:53:47 +0100 Subject: [PATCH] Add a comment about non-atomic B.hPutStrLn --- src/Data/Text/Internal/IO.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Data/Text/Internal/IO.hs b/src/Data/Text/Internal/IO.hs index 9badb3a6..546d3ab6 100644 --- a/src/Data/Text/Internal/IO.hs +++ b/src/Data/Text/Internal/IO.hs @@ -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.