on master help sign in
conduit 0.3
commit8eb70f4984ac950f45f532d85ff840736ce817df authorMichael Snoyman <michael@snoyman.com> dateMon 5 Mar 2012, 11:25 (15 years ago) parent78180d5
4 files changed+16−20
Data/Yaml.hs+2−2 Text/Libyaml.hs+10−15 test/main.hs+1−1 yaml.cabal+3−2
Data/Yaml.hs+2−2
@@ -127,7 +127,7 @@ instance MonadTrans PErrorT where
127127instance MonadIO m => MonadIO (PErrorT m) where
128128 liftIO = lift . liftIO
129129
130−type Parse = StateT (Map.Map String Value) IO
130+type Parse = StateT (Map.Map String Value) (C.ResourceT IO)
131131
132132requireEvent :: Event -> C.Sink Event Parse ()
133133requireEvent e = do
@@ -242,7 +242,7 @@ decodeHelper :: FromJSON a
242242 => C.Source Parse Y.Event
243243 -> IO (Either ParseException (Maybe a))
244244decodeHelper 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
246246 case x of
247247 Left e
248248 | Just pe <- fromException e -> return $ Left pe
Text/Libyaml.hs+10−15
@@ -45,6 +45,7 @@ import Control.Exception (throwIO, Exception, finally)
4545import Control.Applicative
4646import Control.Monad.Trans.Resource
4747import qualified Data.Conduit as C
48+import Control.Exception (mask_)
4849
4950data Event =
5051 EventStreamStart
@@ -451,7 +452,7 @@ newtype ToEventRawException = ToEventRawException CInt
451452 deriving (Show, Typeable)
452453instance Exception ToEventRawException
453454
454−decode :: ResourceIO m => B.ByteString -> C.Source m Event
455+decode :: C.MonadResource m => B.ByteString -> C.Source m Event
455456decode bs =
456457 C.sourceIO alloc cleanup (runParser . fst)
457458 where
@@ -474,7 +475,7 @@ decode bs =
474475 c_yaml_parser_delete ptr
475476 free ptr
476477
477−decodeFile :: ResourceIO m => FilePath -> C.Source m Event
478+decodeFile :: C.MonadResource m => FilePath -> C.Source m Event
478479decodeFile file =
479480 C.sourceIO alloc cleanup (runParser . fst)
480481 where
@@ -505,7 +506,7 @@ decodeFile file =
505506 c_yaml_parser_delete ptr
506507 free ptr
507508
508−runParser :: ResourceIO m => Parser -> m (C.SourceIOResult Event)
509+runParser :: C.MonadResource m => Parser -> m (C.SourceIOResult Event)
509510runParser parser = liftIO $ do
510511 e <- parserParseOne' parser
511512 case e of
@@ -534,7 +535,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
534535 ]
535536 else Right <$> getEvent er
536537
537−encode :: ResourceIO m => C.Sink Event m ByteString
538+encode :: C.MonadResource m => C.Sink Event m ByteString
538539encode =
539540 runEmitter alloc close
540541 where
@@ -549,20 +550,14 @@ encode =
549550 fptr <- newForeignPtr_ $ castPtr ptr'
550551 return $ B.fromForeignPtr fptr 0 $ fromIntegral len
551552
552−encodeFile :: ResourceIO m
553+encodeFile :: C.MonadResource m
553554 => FilePath
554555 -> C.Sink Event m ()
555−encodeFile filePath = C.SinkData
556− { C.sinkPush = \input -> do
557− sink <- msink
558− C.sinkPush sink input
559− , C.sinkClose = do
560− sink <- msink
561− C.sinkClose sink
562− }
556+encodeFile filePath =
557+ C.SinkM msink
563558 where
564559 msink = do
565− (_releaseKey, file) <- flip withIO c_fclose $ do
560+ (_releaseKey, file) <- flip allocate c_fclose $ do
566561 file <- liftIO $ withCString filePath $
567562 \filePath' -> withCString "w" $
568563 \w' -> c_fopen filePath' w'
@@ -574,7 +569,7 @@ encodeFile filePath = C.SinkData
574569 c_yaml_emitter_set_output_file emitter file
575570 return ()
576571
577−runEmitter :: ResourceIO m
572+runEmitter :: C.MonadResource m
578573 => (Emitter -> IO a) -- ^ alloc
579574 -> (a -> IO b) -- ^ close
580575 -> C.Sink Event m b
test/main.hs+1−1
@@ -54,7 +54,7 @@ main = hspecX $ do
5454 it "test mapping merge" caseSimpleMappingMerge
5555 it "test sequence of mappings merging" caseMergeSequence
5656
57−counter :: (Y.Event -> Bool) -> C.Sink Y.Event IO Int
57+counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
5858counter pred' =
5959 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
6060
yaml.cabal+3−2
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.5.2
2+version: 0.6.0
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -30,7 +30,8 @@ library
3030 build-depends: base >= 4 && < 5
3131 , transformers >= 0.1 && < 0.3
3232 , 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
3435 , aeson >= 0.5
3536 , containers
3637 , unordered-containers