From f8b2a1173fa74b1620357487c1a7b299a966cb40 Mon Sep 17 00:00:00 2001 From: "jordi.saludes" Date: Fri, 16 Jul 2010 13:17:49 +0000 Subject: [PATCH] Freeing StablePtr's in PyGF. --- contrib/py-bindings/PyGF.hsc | 14 +++++++++++++- contrib/py-bindings/mtest.c | 9 ++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contrib/py-bindings/PyGF.hsc b/contrib/py-bindings/PyGF.hsc index 7292277dd..2b44e96c9 100644 --- a/contrib/py-bindings/PyGF.hsc +++ b/contrib/py-bindings/PyGF.hsc @@ -9,6 +9,11 @@ import Foreign.C.Types #include "pygf.h" -- type PyPtr = Ptr Py +freeSp :: String -> Ptr a -> IO () +freeSp tname p = do + sp <- (#peek PyGF, sp) p + freeStablePtr sp + putStrLn $ "freeing " ++ tname ++ " at " ++ (show p) instance Storable PGF where sizeOf _ = (#size PyGF) @@ -49,7 +54,14 @@ instance Storable Tree where peek p = do sp <- (#peek PyGF, sp) p deRefStablePtr sp - + +foreign export ccall gf_freePGF :: Ptr PGF -> IO () +foreign export ccall gf_freeType :: Ptr Type -> IO () +foreign export ccall gf_freeLanguage :: Ptr Language -> IO () +gf_freePGF = freeSp "pgf" +gf_freeType = freeSp "type" +gf_freeLanguage = freeSp "language" + {-foreign export ccall gf_printCId :: Ptr CId-> IO CString gf_printCId p = do diff --git a/contrib/py-bindings/mtest.c b/contrib/py-bindings/mtest.c index 1a323468a..58d582389 100644 --- a/contrib/py-bindings/mtest.c +++ b/contrib/py-bindings/mtest.c @@ -56,11 +56,10 @@ int main(int argc, char *argv[]) } while (*p && k < 5); } else puts("no match"); - gf_freeTrees(result); - gf_freeType(cat); - gf_freeLanguage(lang); - gf_freePGF(pgf); */ - + gf_freeTrees(result); */ + gf_freeType(&cat); + gf_freeLanguage(&lang); + gf_freePGF(&pgf); gf_exit(); return 0; }