git.iko.soy/typeable/file-embed
on master help sign in
Use TH 2.16 Bytes literal (#24)
0333940Sylvain Henry
Data/FileEmbed.hs+10−6
@@ -46,11 +46,7 @@ module Data.FileEmbed
46
46
47import Language.Haskell.TH.Syntax
47import Language.Haskell.TH.Syntax
48 ( Exp (AppE, ListE, LitE, TupE, SigE, VarE)
48 ( Exp (AppE, ListE, LitE, TupE, SigE, VarE)
49−#if MIN_VERSION_template_haskell(2,5,0)
49+ , Lit (..)
50− , Lit (StringL, StringPrimL, IntegerL)
51−#else
52− , Lit (StringL, IntegerL)
53−#endif
54 , Q
50 , Q
55 , runIO
51 , runIO
56 , qLocation, loc_filename
52 , qLocation, loc_filename
@@ -58,6 +54,10 @@ import Language.Haskell.TH.Syntax
58 , Quasi(qAddDependentFile)
54 , Quasi(qAddDependentFile)
59#endif
55#endif
60 )
56 )
57+#if MIN_VERSION_template_haskell(2,16,0)
58+import Language.Haskell.TH ( mkBytes, bytesPrimL )
59+import qualified Data.ByteString.Internal as B
60+#endif
61import System.Directory (doesDirectoryExist, doesFileExist,
61import System.Directory (doesDirectoryExist, doesFileExist,
62 getDirectoryContents, canonicalizePath)
62 getDirectoryContents, canonicalizePath)
63import Control.Exception (throw, ErrorCall(..))
63import Control.Exception (throw, ErrorCall(..))
@@ -155,7 +155,11 @@ bsToExp bs =
155 return $ VarE 'unsafePerformIO
155 return $ VarE 'unsafePerformIO
156 `AppE` (VarE 'unsafePackAddressLen
156 `AppE` (VarE 'unsafePackAddressLen
157 `AppE` LitE (IntegerL $ fromIntegral $ B8.length bs)
157 `AppE` LitE (IntegerL $ fromIntegral $ B8.length bs)
158−#if MIN_VERSION_template_haskell(2, 8, 0)
158+#if MIN_VERSION_template_haskell(2, 16, 0)
159+ `AppE` LitE (bytesPrimL (
160+ let B.PS ptr off sz = bs
161+ in mkBytes ptr (fromIntegral off) (fromIntegral sz))))
162+#elif MIN_VERSION_template_haskell(2, 8, 0)
159 `AppE` LitE (StringPrimL $ B.unpack bs))
163 `AppE` LitE (StringPrimL $ B.unpack bs))
160#else
164#else
161 `AppE` LitE (StringPrimL $ B8.unpack bs))
165 `AppE` LitE (StringPrimL $ B8.unpack bs))