on master help sign in
Added fclose call and some exception stuff
commitf9f62459019c2931a57a706cd18033946ffa25af authorMichael Snoyman <michael@snoyman.com> dateTue 12 Jan 2010, 23:15 (17 years ago) parent344b38a
2 files changed+12−5
Text/Libyaml.hs+11−4 yaml.cabal+1−1
Text/Libyaml.hs+11−4
@@ -33,7 +33,7 @@ import Foreign.Ptr
3333import Foreign.ForeignPtr
3434import Foreign.Marshal.Alloc
3535
36−import Control.Exception (throwIO, Exception)
36+import Control.Exception (throwIO, Exception, SomeException)
3737import Data.Typeable (Typeable)
3838
3939data Event =
@@ -103,7 +103,10 @@ data YamlException =
103103 , parserContext :: String
104104 , parserOffset :: Int
105105 }
106− | YamlEmitterException { emitterProblem :: String }
106+ | YamlEmitterException
107+ { emitterEvent :: Event
108+ , emitterProblem :: String
109+ }
107110 | YamlOutOfMemory
108111 | YamlInvalidEventStreamBeginning [Event]
109112 | YamlInvalidEventStreamEnd [Event]
@@ -111,6 +114,7 @@ data YamlException =
111114 | YamlNonScalarKey
112115 | YamlInvalidStartingEvent Event
113116 | YamlFileNotFound FilePath
117+ | YamlOtherException SomeException
114118 deriving (Show, Typeable)
115119instance Exception YamlException
116120
@@ -374,13 +378,16 @@ withEmitterFile fp f = allocaBytes emitterSize $ \e -> do
374378 else do
375379 file <- withCString fp $ \fp' -> withCString "w" $ \w' ->
376380 c_fopen fp' w'
377− if file == nullPtr
381+ res' <-
382+ if file == nullPtr
378383 then return $ Left $ YamlFileNotFound fp
379384 else do
380385 c_yaml_emitter_set_output_file e file
381386 res' <- f e
382387 c_yaml_emitter_delete e
383388 return res'
389+ c_fclose file
390+ return res'
384391
385392foreign import ccall unsafe "yaml_emitter_emit"
386393 c_yaml_emitter_emit :: Emitter -> EventRaw -> IO CInt
@@ -400,7 +407,7 @@ emitEvents unfold src emitter = do
400407 if res == 0
401408 then do
402409 problem <- makeString c_get_emitter_error emitter
403− return $ Left $ YamlEmitterException problem
410+ return $ Left $ YamlEmitterException e problem
404411 else emitEvents unfold src' emitter
405412
406413foreign import ccall unsafe "yaml_stream_start_event_initialize"
yaml.cabal+1−1
@@ -30,7 +30,7 @@ library
3030 build-depends: base >= 4 && < 5,
3131 bytestring >= 0.9.1.4 && < 0.10
3232 exposed-modules: Text.Libyaml
33− ghc-options: -Wall
33+ ghc-options: -Wall -auto-all -caf-all
3434 c-sources: c/helper.c,
3535 c/api.c,
3636 c/dumper.c,