diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index 9a7917f31..5948b0f57 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -100,6 +100,8 @@ struct PgfMarshaller { virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t lit)=0; virtual uintptr_t match_expr(PgfUnmarshaller *u, uintptr_t expr)=0; virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t ty)=0; + virtual void free_ref(uintptr_t x)=0; + virtual void free_me()=0; }; #else typedef struct PgfUnmarshaller PgfUnmarshaller; @@ -133,6 +135,8 @@ struct PgfMarshallerVtbl { uintptr_t (*match_lit)(PgfUnmarshaller *u, uintptr_t lit); uintptr_t (*match_expr)(PgfUnmarshaller *u, uintptr_t expr); uintptr_t (*match_type)(PgfUnmarshaller *u, uintptr_t ty); + void (*free_ref)(PgfUnmarshaller *this, uintptr_t x); + void (*free_me)(PgfUnmarshaller *this); }; struct PgfMarshaller { PgfMarshallerVtbl *vtbl; diff --git a/src/runtime/haskell/PGF2/FFI.hsc b/src/runtime/haskell/PGF2/FFI.hsc index fcf8c1c36..1f22b9946 100644 --- a/src/runtime/haskell/PGF2/FFI.hsc +++ b/src/runtime/haskell/PGF2/FFI.hsc @@ -244,9 +244,13 @@ foreign import ccall "dynamic" foreign import ccall "wrapper" wrapDTypFun :: DTypFun -> IO (FunPtr DTypFun) -foreign import ccall "&hs_free_reference" hs_free_reference :: FunPtr (Ptr PgfUnmarshaller -> StablePtr a -> IO ()) +foreign import ccall "&hs_free_reference" hs_free_reference :: FunPtr (Ptr a -> StablePtr a -> IO ()) -foreign import ccall "&hs_free_unmarshaller" hs_free_unmarshaller :: FunPtr (Ptr PgfUnmarshaller -> IO ()) +foreign import ccall "&hs_free_marshaller" hs_free_marshaller :: FinalizerPtr PgfMarshaller + +foreign import ccall "hs_free_marshaller" freeMarshaller :: Ptr PgfMarshaller -> IO () + +foreign import ccall "&hs_free_unmarshaller" hs_free_unmarshaller :: FinalizerPtr PgfUnmarshaller foreign import ccall "hs_free_unmarshaller" freeUnmarshaller :: Ptr PgfUnmarshaller -> IO () @@ -260,6 +264,8 @@ mkMarshaller = do wrapMatchFun matchLit >>= (#poke PgfMarshallerVtbl, match_lit) vtbl wrapMatchFun matchExpr >>= (#poke PgfMarshallerVtbl, match_expr) vtbl wrapMatchFun matchType >>= (#poke PgfMarshallerVtbl, match_type) vtbl + (#poke PgfMarshallerVtbl, free_ref) vtbl hs_free_reference + (#poke PgfMarshallerVtbl, free_me) vtbl hs_free_marshaller ptr <- mallocBytes (#size PgfMarshaller) (#poke PgfMarshaller, vtbl) ptr vtbl return ptr diff --git a/src/runtime/haskell/utils.c b/src/runtime/haskell/utils.c index 12ed5dbc8..cf1065fb9 100644 --- a/src/runtime/haskell/utils.c +++ b/src/runtime/haskell/utils.c @@ -2,6 +2,15 @@ #include #include +void hs_free_marshaller(PgfMarshaller *marshaller) +{ + hs_free_fun_ptr((HsFunPtr) marshaller->vtbl->match_lit); + hs_free_fun_ptr((HsFunPtr) marshaller->vtbl->match_expr); + hs_free_fun_ptr((HsFunPtr) marshaller->vtbl->match_type); + free(marshaller->vtbl); + free(marshaller); +} + void hs_free_unmarshaller(PgfUnmarshaller *unmarshaller) { hs_free_fun_ptr((HsFunPtr) unmarshaller->vtbl->eabs); @@ -20,7 +29,7 @@ void hs_free_unmarshaller(PgfUnmarshaller *unmarshaller) free(unmarshaller); } -void hs_free_reference(PgfUnmarshaller *unmarshaller, uintptr_t ref) +void hs_free_reference(void *self, uintptr_t ref) { hs_free_stable_ptr((HsStablePtr) ref); }