@@ -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_)
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
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)
@@ -474,7 +475,7 @@ decode bs =
474 c_yaml_parser_delete ptr
475 c_yaml_parser_delete ptr
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)
@@ -505,7 +506,7 @@ decodeFile file =
505 c_yaml_parser_delete ptr
506 c_yaml_parser_delete ptr
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
535 else Right <$> getEvent er
536 else Right <$> getEvent er
537−encode :: ResourceIO m => C.Sink Event m ByteString
538+encode :: C.MonadResource m => C.Sink Event m ByteString
539 runEmitter alloc close
540 runEmitter alloc close
@@ -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
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
558− C.sinkPush sink input
560− sink <- msink
557+ C.SinkM msink
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 ()
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