From 9c45b88e31d9d04fa0b65b2c9c539716ce05372e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 13 Jun 2014 02:18:31 -0400 Subject: 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. --- Build/EvilSplicer.hs | 37 +++++++++++++++++++++++++++++++++ standalone/no-th/evilsplicer-headers.hs | 1 + 2 files changed, 38 insertions(+) diff --git a/Build/EvilSplicer.hs b/Build/EvilSplicer.hs index a8046b994..6b80929af 100644 --- a/Build/EvilSplicer.hs +++ b/Build/EvilSplicer.hs @@ -310,6 +310,7 @@ mangleCode = flip_colon . yesod_url_render_hack . text_builder_hack . nested_instances + . boxed_fileembed . collapse_multiline_strings . remove_package_version . emptylambda @@ -553,6 +554,42 @@ mangleCode = flip_colon - The ; is added by case_layout. -} 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 - type-safe url rendering. - diff --git a/standalone/no-th/evilsplicer-headers.hs b/standalone/no-th/evilsplicer-headers.hs index e02778fcc..2e23df0ce 100644 --- a/standalone/no-th/evilsplicer-headers.hs +++ b/standalone/no-th/evilsplicer-headers.hs @@ -32,6 +32,7 @@ import qualified Network.Wai as Network.Wai.Internal import qualified Yesod.Core.Types import qualified GHC.IO import qualified Data.ByteString.Unsafe +import qualified Data.ByteString.Char8 {- End EvilSplicer headers. -} -- cgit v1.2.3