@@ -4,8 +4,6 @@
4{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
7−{-# INCLUDE <yaml.h> #-}
8−{-# INCLUDE <helper.h> #-}
9module Data.Object.Yaml.Lib
7module Data.Object.Yaml.Lib
10 ( withEmitter
8 ( withEmitter
11 , emitEvents
9 , emitEvents
@@ -29,7 +27,8 @@ import Data.Convertible.Text
29import Control.Applicative
27import Control.Applicative
31import Data.Object.Yaml.Internal
29import Data.Object.Yaml.Internal
32−import Control.Exception (throwIO)
30+import Control.Exception (throwIO, Exception)
31+import Data.Typeable (Typeable)
34data ParserStruct
33data ParserStruct
35type Parser = Ptr ParserStruct
34type Parser = Ptr ParserStruct
@@ -327,7 +326,7 @@ foreign import ccall unsafe "yaml_mapping_end_event_initialize"
328toEventRaw :: Event -> (EventRaw -> IO a) -> IO a
327toEventRaw :: Event -> (EventRaw -> IO a) -> IO a
329toEventRaw e f = withEventRaw $ \er -> do
328toEventRaw e f = withEventRaw $ \er -> do
330− case e of
329+ ret <- case e of
331 EventStreamStart ->
330 EventStreamStart ->
332 c_yaml_stream_start_event_initialize
331 c_yaml_stream_start_event_initialize
@@ -380,8 +379,13 @@ toEventRaw e f = withEventRaw $ \er -> do
380 c_yaml_mapping_end_event_initialize er
379 c_yaml_mapping_end_event_initialize er
381 EventAlias -> error "toEventRaw: EventAlias not supported"
380 EventAlias -> error "toEventRaw: EventAlias not supported"
382 EventNone -> error "toEventRaw: EventNone not supported"
381 EventNone -> error "toEventRaw: EventNone not supported"
382+ unless (ret == 1) $ failure $ ToEventRawException ret
385+newtype ToEventRawException = ToEventRawException CInt
386+ deriving (Show, Typeable)
387+instance Exception ToEventRawException
385encode :: MonadFailure YamlException m
389encode :: MonadFailure YamlException m
386 => [Event]
390 => [Event]
387 -> IO (m B.ByteString)
391 -> IO (m B.ByteString)