Skip to content

Commit

Permalink
declare local OCaml value to the GC in completion bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Mar 7, 2024
1 parent aa311cc commit 150271f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/linenoise_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ CAMLprim value ml_add_completion(value completions, value new_completion)
CAMLreturn(Val_unit);
}

// this bridge runs with the runtime lock acquired
static void completion_bridge_inner(const char *buf, linenoiseCompletions *lc)
{
CAMLparam0();
CAMLlocal1(str_copy);
str_copy = caml_copy_string(buf);
caml_callback2(*caml_named_value("lnoise_completion_cb"), str_copy, (value)lc);
CAMLreturn0;
}

static void completion_bridge(const char *buf, linenoiseCompletions *lc)
{
caml_acquire_runtime_system();
value str_copy = caml_copy_string(buf);
caml_callback2(*caml_named_value("lnoise_completion_cb"), str_copy, (value)lc);
completion_bridge_inner(buf, lc);
caml_release_runtime_system();
}

Expand Down

0 comments on commit 150271f

Please sign in to comment.