make EvilSplicer re-box file-embed's ByteStrings

The armel autobuilder started failing:

Assistant/WebApp/Types.hs:128:14:
    primitive string literal must contain only characters <= '\xFF'

This fixes that.
This commit is contained in:
Joey Hess 2014-06-13 02:18:31 -04:00
parent 96d22a4bac
commit 4dd6938850
2 changed files with 38 additions and 0 deletions

View file

@ -310,6 +310,7 @@ mangleCode = flip_colon
. yesod_url_render_hack . yesod_url_render_hack
. text_builder_hack . text_builder_hack
. nested_instances . nested_instances
. boxed_fileembed
. collapse_multiline_strings . collapse_multiline_strings
. remove_package_version . remove_package_version
. emptylambda . emptylambda
@ -553,6 +554,42 @@ mangleCode = flip_colon
- The ; is added by case_layout. -} - The ; is added by case_layout. -}
flip_colon = replace "; : _ " "; _ : " flip_colon = replace "; : _ " "; _ : "
{- Embedded files use unsafe packing, which is problimatic
- for several reasons, including that GHC sometimes omits trailing
- newlines in the file content, which leads to the wrong byte
- count. Also, GHC sometimes outputs unicode characters, which
- are not legal in unboxed strings.
-
- Avoid problems by converting:
- GHC.IO.unsafePerformIO
- (Data.ByteString.Unsafe.unsafePackAddressLen
- lllll
- "blabblah"#)),
- to:
- Data.ByteString.Char8.pack "blabblah"),
-
- Note that the string is often multiline. This only works if
- collapse_multiline_strings has run first.
-}
boxed_fileembed :: String -> String
boxed_fileembed = parsecAndReplace $ do
i <- indent
void $ string "GHC.IO.unsafePerformIO"
void newline
void indent
void $ string "(Data.ByteString.Unsafe.unsafePackAddressLen"
void newline
void indent
void number
void newline
void indent
void $ char '"'
s <- restOfLine
let s' = take (length s - 5) s
if "\"#))," `isSuffixOf` s
then return (i ++ "Data.ByteString.Char8.pack \"" ++ s' ++ "\"),\n")
else fail "not an unboxed string"
{- This works around a problem in the expanded template haskell for Yesod {- This works around a problem in the expanded template haskell for Yesod
- type-safe url rendering. - type-safe url rendering.
- -

View file

@ -32,6 +32,7 @@ import qualified Network.Wai as Network.Wai.Internal
import qualified Yesod.Core.Types import qualified Yesod.Core.Types
import qualified GHC.IO import qualified GHC.IO
import qualified Data.ByteString.Unsafe import qualified Data.ByteString.Unsafe
import qualified Data.ByteString.Char8
{- End EvilSplicer headers. -} {- End EvilSplicer headers. -}