Skip to content
Snippets Groups Projects
Commit 52c0fc69 authored by PHO's avatar PHO Committed by Marge Bot
Browse files

Don't assume the current locale is *.UTF-8, set the encoding explicitly

primops.txt contains Unicode characters:
> LC_ALL=C ./genprimopcode --data-decl < ./primops.txt
> genprimopcode: <stdin>: hGetContents: invalid argument (cannot decode byte sequence starting from 226)

Hadrian must also avoid using readFile' to read primops.txt because it
tries to decode the file with a locale-specific encoding.
parent 18498538
No related branches found
No related tags found
No related merge requests found
......@@ -333,8 +333,8 @@ instance H.Builder Builder where
GenApply -> captureStdout
GenPrimopCode -> do
stdin <- readFile' input
Stdout stdout <- cmd' (Stdin stdin) [path] buildArgs buildOptions
need [input]
Stdout stdout <- cmd' (FileStdin input) [path] buildArgs buildOptions
-- see Note [Capture stdout as a ByteString]
writeFileChangedBS output stdout
......
......@@ -13,6 +13,7 @@ import Data.Char
import Data.List (union, intersperse, intercalate, nub)
import Data.Maybe ( catMaybes )
import System.Environment ( getArgs )
import System.IO ( hSetEncoding, stdin, stdout, utf8 )
vecOptions :: Entry -> [(String,String,Int)]
vecOptions i =
......@@ -116,7 +117,9 @@ main = getArgs >>= \args ->
++ unlines (map (" "++) known_args)
)
else
do s <- getContents
do hSetEncoding stdin utf8 -- The input file is in UTF-8. Set the encoding explicitly.
hSetEncoding stdout utf8
s <- getContents
case parse s of
Left err -> error ("parse error at " ++ (show err))
Right p_o_specs@(Info _ _)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment