Skip to content

Commit

Permalink
fix: save closure used to create host functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Jan 12, 2024
1 parent 8476649 commit d7448be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/function.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ type t = {
mutable pointer : unit ptr;
mutable user_data : unit ptr;
name : string;
closure :
unit ptr ->
Val.t ptr ->
Unsigned.uint64 ->
Val.t ptr ->
Unsigned.uint64 ->
unit ptr ->
unit;
}

let free t =
Expand Down Expand Up @@ -41,7 +49,9 @@ let create name ?namespace ~params ~results ~user_data f =
let () =
Option.iter (Bindings.extism_function_set_namespace pointer) namespace
in
let t = { pointer; user_data; name; free_lock = Mutex.create () } in
let t =
{ pointer; user_data; name; free_lock = Mutex.create (); closure = f }
in
Gc.finalise_last (fun () -> free t) t;
t

Expand Down

0 comments on commit d7448be

Please sign in to comment.