bugfix in readContext

This commit is contained in:
Krasimir Angelov
2022-07-14 15:56:11 +02:00
parent 9ded2096fd
commit eb41d2661f

View File

@@ -1467,26 +1467,26 @@ readContext str =
n_hypos <- peek p_n_hypos n_hypos <- peek p_n_hypos
if c_hypos == nullPtr && n_hypos /= 0 if c_hypos == nullPtr && n_hypos /= 0
then return Nothing then return Nothing
else do hypos <- peekHypos (castPtrToStablePtr nullPtr) n_hypos c_hypos else do hypos <- peekHypos Nothing n_hypos c_hypos
free c_hypos free c_hypos
return (Just hypos) return (Just hypos)
where where
peekHypos last 0 p_hypo = do peekHypos mb_last 0 p_hypo = do
if last /= castPtrToStablePtr nullPtr case mb_last of
then freeStablePtr last Just last -> freeStablePtr last
else return () _ -> return ()
return [] return []
peekHypos last n_hypos p_hypo = do peekHypos mb_last n_hypos p_hypo = do
bt <- fmap unmarshalBindType ((#peek PgfTypeHypo, bind_type) p_hypo) bt <- fmap unmarshalBindType ((#peek PgfTypeHypo, bind_type) p_hypo)
c_cid <- (#peek PgfTypeHypo, cid) p_hypo c_cid <- (#peek PgfTypeHypo, cid) p_hypo
cid <- peekText c_cid cid <- peekText c_cid
free c_cid free c_cid
c_ty <- (#peek PgfTypeHypo, type) p_hypo c_ty <- (#peek PgfTypeHypo, type) p_hypo
ty <- deRefStablePtr c_ty ty <- deRefStablePtr c_ty
if last /= c_ty case mb_last of
then freeStablePtr last Just last | last /= c_ty -> freeStablePtr last
else return () _ -> return ()
hs <- peekHypos c_ty (n_hypos-1) (p_hypo `plusPtr` (#size PgfTypeHypo)) hs <- peekHypos (Just c_ty) (n_hypos-1) (p_hypo `plusPtr` (#size PgfTypeHypo))
return ((bt,cid,ty):hs) return ((bt,cid,ty):hs)
readProbabilitiesFromFile :: FilePath -> IO (Map.Map String Double) readProbabilitiesFromFile :: FilePath -> IO (Map.Map String Double)