From 0333940019bc8a643fe24d719678bcc5a2bb5898 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Tue, 12 May 2020 09:20:31 +0200 Subject: [PATCH] Use TH 2.16 Bytes literal (#24) --- Data/FileEmbed.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Data/FileEmbed.hs b/Data/FileEmbed.hs index f6cc2a6..267fb77 100644 --- a/Data/FileEmbed.hs +++ b/Data/FileEmbed.hs @@ -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 @@ -58,6 +54,10 @@ import Language.Haskell.TH.Syntax , Quasi(qAddDependentFile) #endif ) +#if MIN_VERSION_template_haskell(2,16,0) +import Language.Haskell.TH ( mkBytes, bytesPrimL ) +import qualified Data.ByteString.Internal as B +#endif import System.Directory (doesDirectoryExist, doesFileExist, getDirectoryContents, canonicalizePath) import Control.Exception (throw, ErrorCall(..)) @@ -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))