Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict-read of file contents and calling hClose #460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Language/Haskell/Exts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ readUTF8File :: FilePath -> IO String
readUTF8File fp = do
h <- openFile fp ReadMode
hSetEncoding h utf8
hGetContents 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.
Expand Down
4 changes: 3 additions & 1 deletion tests/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down