Skip to content

Commit

Permalink
Use TH 2.16 Bytes literal (snoyberg#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyl20 committed May 12, 2020
1 parent ddb1906 commit 16672ba
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Data/FileEmbed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ module Data.FileEmbed

import Language.Haskell.TH.Syntax
( Exp (AppE, ListE, LitE, TupE, SigE, VarE)
#if MIN_VERSION_template_haskell(2,5,0)
, Lit (StringL, StringPrimL, IntegerL)
#else
, Lit (StringL, IntegerL)
#endif
, Lit (..)
, Q
, runIO
, qLocation, loc_filename
Expand All @@ -71,6 +67,10 @@ import System.IO.Unsafe (unsafePerformIO)
import System.FilePath ((</>), takeDirectory, takeExtension)
import Data.String (fromString)
import Prelude as P
#if MIN_VERSION_template_haskell(2,16,0)
import Language.Haskell.TH
import qualified Data.ByteString.Internal as B
#endif

-- | Embed a single file in your source code.
--
Expand Down Expand Up @@ -155,7 +155,11 @@ bsToExp bs =
return $ VarE 'unsafePerformIO
`AppE` (VarE 'unsafePackAddressLen
`AppE` LitE (IntegerL $ fromIntegral $ B8.length bs)
#if MIN_VERSION_template_haskell(2, 8, 0)
#if MIN_VERSION_template_haskell(2, 16, 0)
`AppE` LitE (bytesPrimL (
let B.PS ptr off sz = bs
in mkBytes ptr (fromIntegral off) (fromIntegral sz))))
#elif MIN_VERSION_template_haskell(2, 8, 0)
`AppE` LitE (StringPrimL $ B.unpack bs))
#else
`AppE` LitE (StringPrimL $ B8.unpack bs))
Expand Down

0 comments on commit 16672ba

Please sign in to comment.