From 0923a8f93f597a0f8905985c68a385df5bde017a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Srdic=CC=81?= Date: Wed, 16 Dec 2020 14:53:47 +0100 Subject: [PATCH 1/2] Close file after reading contents. --- src/Language/Haskell/Exts.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Language/Haskell/Exts.hs b/src/Language/Haskell/Exts.hs index f45d3923..0f0ab814 100644 --- a/src/Language/Haskell/Exts.hs +++ b/src/Language/Haskell/Exts.hs @@ -160,7 +160,8 @@ readUTF8File :: FilePath -> IO String readUTF8File fp = do h <- openFile fp ReadMode hSetEncoding h utf8 - hGetContents h + c <- hGetContents h + close h -- | Converts a parse result with comments to a parse result with comments and -- unknown pragmas. From 9dc11dc36c91641df0e1177ec9539cc630eb9bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Srdic=CC=81?= Date: Wed, 16 Dec 2020 16:08:33 +0100 Subject: [PATCH 2/2] Strict read file before closing. --- src/Language/Haskell/Exts.hs | 5 +++-- tests/Runner.hs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Language/Haskell/Exts.hs b/src/Language/Haskell/Exts.hs index 0f0ab814..f278679c 100644 --- a/src/Language/Haskell/Exts.hs +++ b/src/Language/Haskell/Exts.hs @@ -160,8 +160,9 @@ readUTF8File :: FilePath -> IO String readUTF8File fp = do h <- openFile fp ReadMode hSetEncoding h utf8 - c <- hGetContents h - close h + c <- hGetContents h >>= \s -> length s `seq` return s + hClose h + return c -- | Converts a parse result with comments to a parse result with comments and -- unknown pragmas. diff --git a/tests/Runner.hs b/tests/Runner.hs index 424a1618..5cff65b6 100644 --- a/tests/Runner.hs +++ b/tests/Runner.hs @@ -180,7 +180,9 @@ commentsTests dir = testGroup "Comments tests" $ do readUTF8File :: FilePath -> IO String readUTF8File fp = openFile fp ReadMode >>= \h -> do hSetEncoding h utf8 - hGetContents h + c <- hGetContents h >>= \s -> length s `seq` return s + hClose h + return c parseUTF8FileWithComments :: ParseMode -> FilePath -> IO (ParseResult (Module SrcSpanInfo, [Comment])) parseUTF8FileWithComments p fp = readUTF8File fp >>= (return . parseFileContentsWithComments p)