on master help sign in
conduit 0.3
8eb70f4Michael Snoyman
Data/Yaml.hs+2−2
@@ -127,7 +127,7 @@ instance MonadTrans PErrorT where
127instance MonadIO m => MonadIO (PErrorT m) where
127instance MonadIO m => MonadIO (PErrorT m) where
128 liftIO = lift . liftIO
128 liftIO = lift . liftIO
129
129
130−type Parse = StateT (Map.Map String Value) IO
130+type Parse = StateT (Map.Map String Value) (C.ResourceT IO)
131
131
132requireEvent :: Event -> C.Sink Event Parse ()
132requireEvent :: Event -> C.Sink Event Parse ()
133requireEvent e = do
133requireEvent e = do
@@ -242,7 +242,7 @@ decodeHelper :: FromJSON a
242 => C.Source Parse Y.Event
242 => C.Source Parse Y.Event
243 -> IO (Either ParseException (Maybe a))
243 -> IO (Either ParseException (Maybe a))
244decodeHelper src = do
244decodeHelper src = do
245− x <- try $ flip evalStateT Map.empty $ C.runResourceT $ src C.$$ parse
245+ x <- try $ C.runResourceT $ flip evalStateT Map.empty $ src C.$$ parse
246 case x of
246 case x of
247 Left e
247 Left e
248 | Just pe <- fromException e -> return $ Left pe
248 | Just pe <- fromException e -> return $ Left pe
Text/Libyaml.hs+10−15
@@ -45,6 +45,7 @@ import Control.Exception (throwIO, Exception, finally)
45import Control.Applicative
45import Control.Applicative
46import Control.Monad.Trans.Resource
46import Control.Monad.Trans.Resource
47import qualified Data.Conduit as C
47import qualified Data.Conduit as C
48+import Control.Exception (mask_)
48
49
49data Event =
50data Event =
50 EventStreamStart
51 EventStreamStart
@@ -451,7 +452,7 @@ newtype ToEventRawException = ToEventRawException CInt
451 deriving (Show, Typeable)
452 deriving (Show, Typeable)
452instance Exception ToEventRawException
453instance Exception ToEventRawException
453
454
454−decode :: ResourceIO m => B.ByteString -> C.Source m Event
455+decode :: C.MonadResource m => B.ByteString -> C.Source m Event
455decode bs =
456decode bs =
456 C.sourceIO alloc cleanup (runParser . fst)
457 C.sourceIO alloc cleanup (runParser . fst)
457 where
458 where
@@ -474,7 +475,7 @@ decode bs =
474 c_yaml_parser_delete ptr
475 c_yaml_parser_delete ptr
475 free ptr
476 free ptr
476
477
477−decodeFile :: ResourceIO m => FilePath -> C.Source m Event
478+decodeFile :: C.MonadResource m => FilePath -> C.Source m Event
478decodeFile file =
479decodeFile file =
479 C.sourceIO alloc cleanup (runParser . fst)
480 C.sourceIO alloc cleanup (runParser . fst)
480 where
481 where
@@ -505,7 +506,7 @@ decodeFile file =
505 c_yaml_parser_delete ptr
506 c_yaml_parser_delete ptr
506 free ptr
507 free ptr
507
508
508−runParser :: ResourceIO m => Parser -> m (C.SourceIOResult Event)
509+runParser :: C.MonadResource m => Parser -> m (C.SourceIOResult Event)
509runParser parser = liftIO $ do
510runParser parser = liftIO $ do
510 e <- parserParseOne' parser
511 e <- parserParseOne' parser
511 case e of
512 case e of
@@ -534,7 +535,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
534 ]
535 ]
535 else Right <$> getEvent er
536 else Right <$> getEvent er
536
537
537−encode :: ResourceIO m => C.Sink Event m ByteString
538+encode :: C.MonadResource m => C.Sink Event m ByteString
538encode =
539encode =
539 runEmitter alloc close
540 runEmitter alloc close
540 where
541 where
@@ -549,20 +550,14 @@ encode =
549 fptr <- newForeignPtr_ $ castPtr ptr'
550 fptr <- newForeignPtr_ $ castPtr ptr'
550 return $ B.fromForeignPtr fptr 0 $ fromIntegral len
551 return $ B.fromForeignPtr fptr 0 $ fromIntegral len
551
552
552−encodeFile :: ResourceIO m
553+encodeFile :: C.MonadResource m
553 => FilePath
554 => FilePath
554 -> C.Sink Event m ()
555 -> C.Sink Event m ()
555−encodeFile filePath = C.SinkData
556+encodeFile filePath =
556− { C.sinkPush = \input -> do
557− sink <- msink
558− C.sinkPush sink input
559− , C.sinkClose = do
560− sink <- msink
557+ C.SinkM msink
561− C.sinkClose sink
562− }
563 where
558 where
564 msink = do
559 msink = do
565− (_releaseKey, file) <- flip withIO c_fclose $ do
560+ (_releaseKey, file) <- flip allocate c_fclose $ do
566 file <- liftIO $ withCString filePath $
561 file <- liftIO $ withCString filePath $
567 \filePath' -> withCString "w" $
562 \filePath' -> withCString "w" $
568 \w' -> c_fopen filePath' w'
563 \w' -> c_fopen filePath' w'
@@ -574,7 +569,7 @@ encodeFile filePath = C.SinkData
574 c_yaml_emitter_set_output_file emitter file
569 c_yaml_emitter_set_output_file emitter file
575 return ()
570 return ()
576
571
577−runEmitter :: ResourceIO m
572+runEmitter :: C.MonadResource m
578 => (Emitter -> IO a) -- ^ alloc
573 => (Emitter -> IO a) -- ^ alloc
579 -> (a -> IO b) -- ^ close
574 -> (a -> IO b) -- ^ close
580 -> C.Sink Event m b
575 -> C.Sink Event m b
test/main.hs+1−1
@@ -54,7 +54,7 @@ main = hspecX $ do
54 it "test mapping merge" caseSimpleMappingMerge
54 it "test mapping merge" caseSimpleMappingMerge
55 it "test sequence of mappings merging" caseMergeSequence
55 it "test sequence of mappings merging" caseMergeSequence
56
56
57−counter :: (Y.Event -> Bool) -> C.Sink Y.Event IO Int
57+counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
58counter pred' =
58counter pred' =
59 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
59 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
60
60
yaml.cabal+3−2
@@ -1,5 +1,5 @@
1name: yaml
1name: yaml
2−version: 0.5.2
2+version: 0.6.0
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
5author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -30,7 +30,8 @@ library
30 build-depends: base >= 4 && < 5
30 build-depends: base >= 4 && < 5
31 , transformers >= 0.1 && < 0.3
31 , transformers >= 0.1 && < 0.3
32 , bytestring >= 0.9.1.4 && < 0.10
32 , bytestring >= 0.9.1.4 && < 0.10
33− , conduit >= 0.2 && < 0.3
33+ , conduit >= 0.3 && < 0.4
34+ , resourcet >= 0.3 && < 0.4
34 , aeson >= 0.5
35 , aeson >= 0.5
35 , containers
36 , containers
36 , unordered-containers
37 , unordered-containers