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

Fix #96 Write files with utf8 encoding, not, effectively, char8 #97

Open
wants to merge 1 commit 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
6 changes: 4 additions & 2 deletions src/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ default_compiler = "cc"
------------------------------------------------------------------------
-- Write the output files.

writeBinaryFile :: FilePath -> String -> IO ()
writeBinaryFile fp str = withBinaryFile fp WriteMode $ \h -> hPutStr h str
writeUtf8File :: FilePath -> String -> IO ()
writeUtf8File fp str = withBinaryFile fp WriteMode $ \h -> do
hSetEncoding h utf8
hPutStr h str

rawSystemL :: FilePath -> FilePath -> String -> Bool -> FilePath -> [String] -> IO ()
rawSystemL outDir outBase action flg prog args = withResponseFile outDir outBase args $ \rspFile -> do
Expand Down
6 changes: 3 additions & 3 deletions src/CrossCodegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ checkValidity input = do
concatMap (uncurry (outValidityCheck (cViaAsm config))) (zip input [0..])
testLog ("checking for compilation errors") $ do
success <- makeTest2 (".c",".o") $ \(cFile,oFile) -> do
liftTestIO $ writeBinaryFile cFile test
liftTestIO $ writeUtf8File cFile test
compiler <- testGetCompiler
runCompiler compiler
(["-S" | cViaAsm config ]++
Expand Down Expand Up @@ -619,7 +619,7 @@ runCompileAsmIntegerTest _ = error "runCompileAsmIntegerTestargument isn't a Spe
runCompileExtract :: String -> String -> TestMonad Integer
runCompileExtract k testStr = do
makeTest3 (".c", ".s", ".txt") $ \(cFile, sFile, stdout) -> do
liftTestIO $ writeBinaryFile cFile testStr
liftTestIO $ writeUtf8File cFile testStr
flags <- testGetFlags
compiler <- testGetCompiler
_ <- runCompiler compiler
Expand All @@ -631,7 +631,7 @@ runCompileExtract k testStr = do
runCompileTest :: String -> TestMonad Bool
runCompileTest testStr = do
makeTest3 (".c", ".o",".txt") $ \(cFile,oFile,stdout) -> do
liftTestIO $ writeBinaryFile cFile testStr
liftTestIO $ writeUtf8File cFile testStr
flags <- testGetFlags
compiler <- testGetCompiler
runCompiler compiler
Expand Down
6 changes: 3 additions & 3 deletions src/DirectCodegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ outputDirect config outName outDir outBase name toks = do
"if","ifdef","ifndef", "elif","else","endif"]) $
die (file ++ ":" ++ show line ++ " directive \"" ++ key ++ "\" is not safe for cross-compilation"))

writeBinaryFile cProgName $
writeUtf8File cProgName $
outTemplateHeaderCProg (cTemplate config)++
concatMap outFlagHeaderCProg flags++
concatMap outHeaderCProg specials++
Expand Down Expand Up @@ -99,7 +99,7 @@ outputDirect config outName outDir outBase name toks = do
rawSystemWithStdOutL outDir outBase ("running " ++ execProgName) beVerbose execProgName [] outName
possiblyRemove progName $ do

when needsH $ writeBinaryFile outHName $
when needsH $ writeUtf8File outHName $
"#ifndef "++includeGuard++"\n" ++
"#define "++includeGuard++"\n" ++
"#include <HsFFI.h>\n" ++
Expand All @@ -111,7 +111,7 @@ outputDirect config outName outDir outBase name toks = do
concatMap outTokenH specials++
"#endif\n"

when needsC $ writeBinaryFile outCName $
when needsC $ writeUtf8File outCName $
"#include \""++outHFile++"\"\n"++
concatMap outTokenC specials
-- NB. outHFile not outHName; works better when processed
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCodegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ withUtilsObject config outDir outBase f = do
oUtilsName = outDir ++ outBase ++ "_hsc_utils.o"

possiblyRemove cUtilsName $ do
writeBinaryFile cUtilsName $ unlines $
writeUtf8File cUtilsName $ unlines $
-- These header will cause a mismatch with any mingw-w64 header by
-- including system headers before user headers in the hsc file.
-- We *MUST* include user headers *BEFORE* automatic ones. */
Expand Down
Loading