free_ref & free_me in PgfMarshaller too

This commit is contained in:
krangelov
2021-08-14 20:08:04 +02:00
parent 9db352b2bb
commit 8b8028bdfe
3 changed files with 22 additions and 3 deletions

View File

@@ -100,6 +100,8 @@ struct PgfMarshaller {
virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t lit)=0; 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_expr(PgfUnmarshaller *u, uintptr_t expr)=0;
virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t ty)=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 #else
typedef struct PgfUnmarshaller PgfUnmarshaller; typedef struct PgfUnmarshaller PgfUnmarshaller;
@@ -133,6 +135,8 @@ struct PgfMarshallerVtbl {
uintptr_t (*match_lit)(PgfUnmarshaller *u, uintptr_t lit); uintptr_t (*match_lit)(PgfUnmarshaller *u, uintptr_t lit);
uintptr_t (*match_expr)(PgfUnmarshaller *u, uintptr_t expr); uintptr_t (*match_expr)(PgfUnmarshaller *u, uintptr_t expr);
uintptr_t (*match_type)(PgfUnmarshaller *u, uintptr_t ty); uintptr_t (*match_type)(PgfUnmarshaller *u, uintptr_t ty);
void (*free_ref)(PgfUnmarshaller *this, uintptr_t x);
void (*free_me)(PgfUnmarshaller *this);
}; };
struct PgfMarshaller { struct PgfMarshaller {
PgfMarshallerVtbl *vtbl; PgfMarshallerVtbl *vtbl;

View File

@@ -244,9 +244,13 @@ foreign import ccall "dynamic"
foreign import ccall "wrapper" foreign import ccall "wrapper"
wrapDTypFun :: DTypFun -> IO (FunPtr DTypFun) 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 () foreign import ccall "hs_free_unmarshaller" freeUnmarshaller :: Ptr PgfUnmarshaller -> IO ()
@@ -260,6 +264,8 @@ mkMarshaller = do
wrapMatchFun matchLit >>= (#poke PgfMarshallerVtbl, match_lit) vtbl wrapMatchFun matchLit >>= (#poke PgfMarshallerVtbl, match_lit) vtbl
wrapMatchFun matchExpr >>= (#poke PgfMarshallerVtbl, match_expr) vtbl wrapMatchFun matchExpr >>= (#poke PgfMarshallerVtbl, match_expr) vtbl
wrapMatchFun matchType >>= (#poke PgfMarshallerVtbl, match_type) 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) ptr <- mallocBytes (#size PgfMarshaller)
(#poke PgfMarshaller, vtbl) ptr vtbl (#poke PgfMarshaller, vtbl) ptr vtbl
return ptr return ptr

View File

@@ -2,6 +2,15 @@
#include <pgf/pgf.h> #include <pgf/pgf.h>
#include <stdlib.h> #include <stdlib.h>
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) void hs_free_unmarshaller(PgfUnmarshaller *unmarshaller)
{ {
hs_free_fun_ptr((HsFunPtr) unmarshaller->vtbl->eabs); hs_free_fun_ptr((HsFunPtr) unmarshaller->vtbl->eabs);
@@ -20,7 +29,7 @@ void hs_free_unmarshaller(PgfUnmarshaller *unmarshaller)
free(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); hs_free_stable_ptr((HsStablePtr) ref);
} }