use interleaved IO for peeking strings when possible

This commit is contained in:
Krasimir Angelov
2018-11-14 15:52:44 +01:00
parent 7239a45ac5
commit fd2aa96e65
5 changed files with 80 additions and 62 deletions

View File

@@ -252,14 +252,14 @@ foreign import ccall "wrapper"
-- of binding.
showExpr :: [CId] -> Expr -> String
showExpr scope e =
unsafePerformIO $
withGuPool $ \tmpPl ->
do (sb,out) <- newOut tmpPl
printCtxt <- newPrintCtxt scope tmpPl
exn <- gu_new_exn tmpPl
pgf_print_expr (expr e) printCtxt 1 out exn
touchExpr e
peekUtf8CStringBuf sb
unsafePerformIO $ do
tmpPl <- gu_new_pool
(sb,out) <- newOut tmpPl
printCtxt <- newPrintCtxt scope tmpPl
exn <- gu_new_exn tmpPl
pgf_print_expr (expr e) printCtxt 1 out exn
touchExpr e
peekUtf8CStringBufResult sb tmpPl
newPrintCtxt :: [String] -> Ptr GuPool -> IO (Ptr PgfPrintContext)
newPrintCtxt [] pool = return nullPtr