From 26aecdb4d30a3dc433bfda9863bab9a47992886e Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 10 Jun 2014 12:42:01 +0000 Subject: [PATCH] PGF2.hsc: use throwIO instead of throw From the documentation: the throwIO variant should be used in preference to throw to raise an exception within the IO monad because it guarantees ordering with respect to other IO operations, whereas throw does not. Also removed some unused imports. --- src/runtime/haskell-bind/PGF2.hsc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc index 42d49deb4..d76e86a5d 100644 --- a/src/runtime/haskell-bind/PGF2.hsc +++ b/src/runtime/haskell-bind/PGF2.hsc @@ -16,18 +16,14 @@ module PGF2 (-- * PGF ) where import Prelude hiding (fromEnum) -import Control.Exception ---import System.IO -import System.IO.Unsafe +import Control.Exception(Exception,throwIO) +import System.IO.Unsafe(unsafePerformIO,unsafeInterleaveIO) import PGF2.FFI import Foreign hiding ( Pool, newPool, unsafePerformIO ) import Foreign.C ---import Foreign.C.String ---import Foreign.Ptr import Data.Typeable import qualified Data.Map as Map ---import qualified Data.ByteString as BS import Data.IORef @@ -58,7 +54,7 @@ readPGF fpath = gu_pool_free pool ioError (errnoToIOError "readPGF" (Errno errno) Nothing (Just fpath)) else do gu_pool_free pool - throw (PGFError "The grammar cannot be loaded") + throwIO (PGFError "The grammar cannot be loaded") else return pgf master <- newForeignPtr gu_pool_finalizer pool return PGF {pgf = pgf, pgfMaster = master} @@ -225,10 +221,10 @@ parse lang cat sent = msg <- peekCString c_msg gu_pool_free parsePl gu_pool_free exprPl - throw (PGFError msg) + throwIO (PGFError msg) else do gu_pool_free parsePl gu_pool_free exprPl - throw (PGFError "Parsing failed") + throwIO (PGFError "Parsing failed") else do parseFPl <- newForeignPtr gu_pool_finalizer parsePl exprFPl <- newForeignPtr gu_pool_finalizer exprPl exprs <- fromPgfExprEnum enum parseFPl (lang,exprFPl) @@ -248,8 +244,8 @@ linearize lang e = unsafePerformIO $ else if ty == gu_type__PgfExn then do c_msg <- (#peek GuExn, data.data) exn msg <- peekCString c_msg - throw (PGFError msg) - else throw (PGFError "The abstract tree cannot be linearized") + throwIO (PGFError msg) + else throwIO (PGFError "The abstract tree cannot be linearized") else do lin <- gu_string_buf_freeze sb pl peekCString lin