Browse files

Fix major bug where awaitForever was wrongly used

... and was resulting in nested (!) recursion and a major accompanying
space leak due to retained stream elements.
  • Loading branch information...
1 parent e28a12d commit e653621f41efd1119cf19b46707c6b30ea5becae @ozataman committed Mar 22, 2013
Showing with 5 additions and 11 deletions.
  1. +1 −1 csv-conduit.cabal
  2. +4 −10 src/Data/CSV/Conduit.hs
View
2 csv-conduit.cabal
@@ -1,5 +1,5 @@
Name: csv-conduit
-Version: 0.5.0
+Version: 0.5.1
Synopsis: A flexible, fast, conduit-based CSV parser library for Haskell.
Homepage: http://github.com/ozataman/csv-conduit
License: BSD3
View
14 src/Data/CSV/Conduit.hs
@@ -166,9 +166,7 @@ instance CSV ByteString (Row String) where
-------------------------------------------------------------------------------
fromCSVRow :: (Monad m, IsString s, CSV s r)
=> CSVSettings -> Conduit r m s
-fromCSVRow set = awaitForever $ \row -> do
- mapM_ yield [rowToStr set row, "\n"]
- fromCSVRow set
+fromCSVRow set = awaitForever $ \row -> mapM_ yield [rowToStr set row, "\n"]
-------------------------------------------------------------------------------
@@ -178,11 +176,7 @@ intoCSVRow p = parse =$= puller
where
parse = {-# SCC "conduitParser_p" #-} conduitParser p
puller = {-# SCC "puller" #-}
- awaitForever $ \ (_, mrow) ->
- case mrow of
- Just row -> yield row >> puller
- Nothing -> puller
-
+ awaitForever $ \ (_, mrow) -> maybe (return ()) yield mrow
-------------------------------------------------------------------------------
@@ -205,14 +199,14 @@ intoCSVMap set = intoCSV set =$= (headers >>= converter)
Nothing -> return []
Just [] -> headers
Just hs -> return hs
- converter hs = awaitForever $ \row -> yield (toMapCSV hs row) >> converter hs
+ converter hs = awaitForever $ yield . toMapCSV hs
toMapCSV !hs !fs = M.fromList $ zip hs fs
-------------------------------------------------------------------------------
fromCSVMap :: (Monad m, IsString s, CSV s [a])
=> CSVSettings -> Conduit (M.Map k a) m s
-fromCSVMap set = awaitForever $ \row -> push row >> fromCSVMap set
+fromCSVMap set = awaitForever push
where
push r = mapM_ yield [rowToStr set (M.elems r), "\n"]

0 comments on commit e653621

Please sign in to comment.