diff --git a/Blaze/ByteString/Builder.hs b/Blaze/ByteString/Builder.hs index 9cc61c2..3163ea5 100644 --- a/Blaze/ByteString/Builder.hs +++ b/Blaze/ByteString/Builder.hs @@ -1,5 +1,7 @@ {-# LANGUAGE CPP, BangPatterns #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Trustworthy #-} +#endif ------------------------------------------------------------------------------ -- | diff --git a/Blaze/ByteString/Builder/ByteString.hs b/Blaze/ByteString/Builder/ByteString.hs index 9962253..3782558 100644 --- a/Blaze/ByteString/Builder/ByteString.hs +++ b/Blaze/ByteString/Builder/ByteString.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Trustworthy #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.ByteString @@ -33,24 +38,14 @@ module Blaze.ByteString.Builder.ByteString ) where +import Blaze.ByteString.Builder.Internal.Write (writeByteString) -import Blaze.ByteString.Builder.Internal.Write ( Write, exactWrite ) -import Foreign import qualified Data.ByteString.Builder as B import qualified Data.ByteString.Builder.Extra as B import qualified Data.ByteString as S -import qualified Data.ByteString.Internal as S import qualified Data.ByteString.Lazy as L --- | Write a strict 'S.ByteString' to a buffer. -writeByteString :: S.ByteString -> Write -writeByteString bs = exactWrite l io - where - (fptr, o, l) = S.toForeignPtr bs - io pf = withForeignPtr fptr $ \p -> copyBytes pf (p `plusPtr` o) l -{-# INLINE writeByteString #-} - -- | Create a 'B.Builder' denoting the same sequence of bytes as a strict -- 'S.ByteString'. -- The 'B.Builder' inserts large 'S.ByteString's directly, but copies small ones diff --git a/Blaze/ByteString/Builder/Char/Utf8.hs b/Blaze/ByteString/Builder/Char/Utf8.hs index c14db6c..fd58b4b 100644 --- a/Blaze/ByteString/Builder/Char/Utf8.hs +++ b/Blaze/ByteString/Builder/Char/Utf8.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Safe #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.Char.Utf8 diff --git a/Blaze/ByteString/Builder/Char8.hs b/Blaze/ByteString/Builder/Char8.hs index fe932bc..957b248 100644 --- a/Blaze/ByteString/Builder/Char8.hs +++ b/Blaze/ByteString/Builder/Char8.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Safe #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.Char8 diff --git a/Blaze/ByteString/Builder/Compat/Write.hs b/Blaze/ByteString/Builder/Compat/Write.hs index 6d43bb1..5081f32 100644 --- a/Blaze/ByteString/Builder/Compat/Write.hs +++ b/Blaze/ByteString/Builder/Compat/Write.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Trustworthy #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.Compat.Write diff --git a/Blaze/ByteString/Builder/HTTP.hs b/Blaze/ByteString/Builder/HTTP.hs index 78b904a..be4520a 100644 --- a/Blaze/ByteString/Builder/HTTP.hs +++ b/Blaze/ByteString/Builder/HTTP.hs @@ -1,4 +1,7 @@ {-# LANGUAGE BangPatterns, CPP, MagicHash, OverloadedStrings #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Trustworthy #-} +#endif ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.HTTP diff --git a/Blaze/ByteString/Builder/Html/Utf8.hs b/Blaze/ByteString/Builder/Html/Utf8.hs index ecdb5d6..23e20fd 100644 --- a/Blaze/ByteString/Builder/Html/Utf8.hs +++ b/Blaze/ByteString/Builder/Html/Utf8.hs @@ -2,6 +2,9 @@ #if __GLASGOW_HASKELL__ >= 704 {-# OPTIONS_GHC -fsimpl-tick-factor=40000 #-} #endif +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Safe #-} +#endif ------------------------------------------------------------------------------ -- | diff --git a/Blaze/ByteString/Builder/Int.hs b/Blaze/ByteString/Builder/Int.hs index 57ba7e7..c2655af 100644 --- a/Blaze/ByteString/Builder/Int.hs +++ b/Blaze/ByteString/Builder/Int.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Safe #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.Int diff --git a/Blaze/ByteString/Builder/Internal/Write.hs b/Blaze/ByteString/Builder/Internal/Write.hs index 0e6045e..290b9ff 100644 --- a/Blaze/ByteString/Builder/Internal/Write.hs +++ b/Blaze/ByteString/Builder/Internal/Write.hs @@ -1,4 +1,7 @@ {-# LANGUAGE CPP, BangPatterns #-} +#if __GLASGOW_HASKELL__ >= 704 +{-# LANGUAGE Unsafe #-} +#endif -- | -- Module : Blaze.ByteString.Builder.Internal.Poke @@ -45,6 +48,7 @@ module Blaze.ByteString.Builder.Internal.Write ( , fromStorable , fromStorables + , writeByteString ) where import Foreign @@ -52,6 +56,7 @@ import Foreign import Control.Monad import Data.ByteString.Builder.Internal +import Data.ByteString.Internal as S #if !MIN_VERSION_base(4,8,0) import Data.Monoid @@ -286,3 +291,11 @@ fromStorable = fromWriteSingleton writeStorable -- provided externally. fromStorables :: Storable a => [a] -> Builder fromStorables = fromWriteList writeStorable + +-- | Write a strict 'S.ByteString' to a buffer. +writeByteString :: S.ByteString -> Write +writeByteString bs = exactWrite l io + where + (fptr, o, l) = S.toForeignPtr bs + io pf = withForeignPtr fptr $ \p -> copyBytes pf (p `plusPtr` o) l +{-# INLINE writeByteString #-} diff --git a/Blaze/ByteString/Builder/Word.hs b/Blaze/ByteString/Builder/Word.hs index 670a224..98823c6 100644 --- a/Blaze/ByteString/Builder/Word.hs +++ b/Blaze/ByteString/Builder/Word.hs @@ -1,3 +1,8 @@ +{-# LANGUAGE CPP #-} +#if __GLASGOW_HASKELL__ >= 702 +{-# LANGUAGE Safe #-} +#endif + ------------------------------------------------------------------------------ -- | -- Module: Blaze.ByteString.Builder.Word diff --git a/CHANGES b/CHANGES index 31f2af4..704684e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +* 0.4.1.0 + - Add Safe Haskell pragmas + * 0.4.0.2 - Fixed warnings on GHC 7.10, courtesy of Mikhail Glushenkov. diff --git a/blaze-builder.cabal b/blaze-builder.cabal index 4c3a869..269c4ac 100644 --- a/blaze-builder.cabal +++ b/blaze-builder.cabal @@ -1,5 +1,5 @@ Name: blaze-builder -Version: 0.4.0.2 +Version: 0.4.1.0 Synopsis: Efficient buffered output. Description: