Skip to content

Commit

Permalink
Merge pull request #22 from lpsmith/compat
Browse files Browse the repository at this point in the history
Latest compat work. Thanks @lpsmith the code has become a lot smaller, which I like. One thing I noticed is that we should add a big disclaimer to the documentation pointing people to the proper bytestring builder, which they should use in new projects.
  • Loading branch information
meiersi committed Jan 30, 2015
2 parents f482409 + 1869752 commit 722de5d
Show file tree
Hide file tree
Showing 28 changed files with 26 additions and 120 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- Module: Blaze.ByteString.Builder
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- "Blaze.ByteString.Builder" is the main module, which you should import as a user
Expand Down
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.ByteString
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- 'Write's and 'B.Builder's for strict and lazy bytestrings.
Expand Down
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/Char/Utf8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.Char.Utf8
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- 'Write's and 'Builder's for serializing Unicode characters using the UTF-8
Expand Down
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/Char8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.Char8
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- //Note:// This package is intended for low-level use like implementing
Expand Down
12 changes: 5 additions & 7 deletions Blaze/ByteString/Builder/Compat/Write.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.Compat.Write
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- Conversions from the new Prims to the old Writes.
Expand All @@ -21,11 +21,9 @@ import Data.ByteString.Builder.Prim.Internal
import Blaze.ByteString.Builder.Internal.Write

writePrimFixed :: FixedPrim a -> a -> Write
writePrimFixed fe a = Write (size fe) (Poke wio)
where wio op = do
runF fe a op
return $! (op `plusPtr` size fe)
writePrimFixed fe a = exactWrite (size fe) (runF fe a)
{-# INLINE writePrimFixed #-}

writePrimBounded :: BoundedPrim a -> a -> Write
writePrimBounded be a = Write (sizeBound be) (Poke wio)
where wio = runB be a
writePrimBounded be a = boundedWrite (sizeBound be) (Poke (runB be a))
{-# INLINE writePrimBounded #-}
8 changes: 6 additions & 2 deletions Blaze/ByteString/Builder/Html/Utf8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- Module: Blaze.ByteString.Builder.Html.Utf8
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- 'Write's and 'Builder's for serializing HTML escaped and UTF-8 encoded
Expand Down Expand Up @@ -67,7 +67,7 @@ charUtf8HtmlEscaped =
condB (== '<' ) (fixed4 ('&',('l',('t',';')))) $ -- &lt;
condB (== '>' ) (fixed4 ('&',('g',('t',';')))) $ -- &gt;
condB (== '&' ) (fixed5 ('&',('a',('m',('p',';'))))) $ -- &amp;
condB (== '"' ) (fixed5 ('&',('#',('3',('4',';'))))) $ -- &#34;
condB (== '"' ) (fixed6 ('&',('q',('u',('o',('t',';')))))) $ -- &#quot;
condB (== '\'') (fixed5 ('&',('#',('3',('9',';'))))) $ -- &#39;
condB (\c -> c >= ' ' || c == '\t' || c == '\n' || c == '\r')
(P.liftFixedToBounded P.char7) $
Expand All @@ -81,6 +81,10 @@ charUtf8HtmlEscaped =
fixed5 x = P.liftFixedToBounded $ const x >$<
P.char7 >*< P.char7 >*< P.char7 >*< P.char7 >*< P.char7

{-# INLINE fixed6 #-}
fixed6 x = P.liftFixedToBounded $ const x >$<
P.char7 >*< P.char7 >*< P.char7 >*< P.char7 >*< P.char7 >*< P.char7

-- | /O(n)/. Serialize a HTML escaped Unicode 'String' using the UTF-8
-- encoding.
--
Expand Down
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/Int.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.Int
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- 'Write's and 'Builder's for serializing integers.
Expand Down
4 changes: 2 additions & 2 deletions Blaze/ByteString/Builder/Internal/Write.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- (c) 2010 Jasper van der Jeugt
-- License : BSD3-style (see LICENSE)
--
-- Maintainer : Leon P Smith <leon@melding-monads.com>
-- Maintainer : Simon Meier <iridcode@gmail.com>
-- Stability : experimental
-- Portability : tested on GHC only
--
Expand Down Expand Up @@ -145,7 +145,7 @@ instance Monoid Write where
{-# INLINE pokeN #-}
pokeN :: Int
-> (Ptr Word8 -> IO ()) -> Poke
pokeN size io = Poke $ \op -> io op >> return (op `plusPtr` size)
pokeN size io = Poke $ \op -> io op >> (return $! (op `plusPtr` size))


-- | @exactWrite size io@ creates a bounded write that can later be converted to
Expand Down
2 changes: 1 addition & 1 deletion Blaze/ByteString/Builder/Word.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Module: Blaze.ByteString.Builder.Word
-- Copyright: (c) 2013 Leon P Smith
-- License: BSD3
-- Maintainer: Leon P Smith <leon@melding-monads.com>
-- Maintainer: Simon Meier <iridcode@gmail.com>
-- Stability: experimental
--
-- 'Write's and 'Builder's for serializing words.
Expand Down
1 change: 0 additions & 1 deletion Data/ByteString/Builder.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/ASCII.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Extra.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Internal.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/ASCII.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/Binary.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/Internal.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/Internal/Base16.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/Internal/Floating.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Builder/Prim/Internal/UncheckedShifts.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Short.hs

This file was deleted.

1 change: 0 additions & 1 deletion Data/ByteString/Short/Internal.hs

This file was deleted.

40 changes: 1 addition & 39 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,40 +1,2 @@
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import Distribution.Version

-- This checks the direct dependency of the bytestring package being
-- compiled against to set the bytestring_has_itoa_c and
-- bytestring_has_builder flags accordingly.

main = defaultMainWithHooks simpleUserHooks {
confHook = \pkg flags ->
if null (configConstraints flags)
then do
confHook simpleUserHooks pkg flags
else do
let bytestring_version =
case [ versionBranch v
| (Dependency pkg ver) <- configConstraints flags
, pkg == PackageName "bytestring"
, (Just v) <- [isSpecificVersion ver] ]
of
[v] -> v
vs -> error ("error detecting bytestring version " ++ show vs)

let has_itoa_c = ( FlagName "bytestring_has_itoa_c"
, bytestring_version >= [0,10] )

let has_builder = ( FlagName "bytestring_has_builder"
, bytestring_version >= [0,10,4] )

let update fs gs =
fs ++ [ g | g <- gs, not $ any (\f -> fst f == fst g) fs]

let flags' = flags { configConfigurationsFlags =
update [has_itoa_c, has_builder]
(configConfigurationsFlags flags) }

confHook simpleUserHooks pkg flags'
}
main = defaultMain
43 changes: 6 additions & 37 deletions blaze-builder.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Bug-Reports: http://github.com/meiersi/blaze-builder/issues
Stability: Experimental

Category: Data
Build-type: Custom
Build-type: Simple
Cabal-version: >= 1.8

Extra-source-files:
Expand Down Expand Up @@ -55,15 +55,7 @@ Source-repository head
Type: git
Location: https://github.com/meiersi/blaze-builder.git

-- Note that these flags are set by Setup.hs

Flag bytestring_has_itoa_c
default: True
manual: True

Flag bytestring_has_builder
default: True
manual: True
-- Note that this flag is set by Setup.hs

Library
ghc-options: -Wall
Expand All @@ -81,35 +73,12 @@ Library
Blaze.ByteString.Builder.Internal.Write

build-depends: base == 4.* ,
bytestring >= 0.9 && < 1.0 ,
bytestring >= 0.9 && < 1.0,
deepseq,
text >= 0.10 && < 0.13

if !flag(bytestring_has_itoa_c)
c-sources: cbits/itoa.c


if !flag(bytestring_has_builder)
c-sources: cbits/fpstring.c
exposed-modules:
Data.ByteString.Builder
Data.ByteString.Builder.Extra
Data.ByteString.Builder.Prim

-- perhaps only exposed temporarily
Data.ByteString.Builder.Internal
Data.ByteString.Builder.Prim.Internal

Data.ByteString.Short
Data.ByteString.Short.Internal
text >= 0.10

other-modules:
Data.ByteString.Builder.ASCII
Data.ByteString.Builder.Prim.Binary
Data.ByteString.Builder.Prim.ASCII
Data.ByteString.Builder.Prim.Internal.Floating
Data.ByteString.Builder.Prim.Internal.UncheckedShifts
Data.ByteString.Builder.Prim.Internal.Base16
if impl(ghc < 7.8)
build-depends: bytestring-builder

test-suite test
type: exitcode-stdio-1.0
Expand Down
1 change: 0 additions & 1 deletion bytestring
Submodule bytestring deleted from f0bac1
9 changes: 0 additions & 9 deletions cbits/fpstring.c

This file was deleted.

1 change: 0 additions & 1 deletion cbits/itoa.c

This file was deleted.

0 comments on commit 722de5d

Please sign in to comment.