Skip to content

Commit 150271f

Browse files
committed
declare local OCaml value to the GC in completion bridge
1 parent aa311cc commit 150271f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/linenoise_stubs.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@ CAMLprim value ml_add_completion(value completions, value new_completion)
4242
CAMLreturn(Val_unit);
4343
}
4444

45+
// this bridge runs with the runtime lock acquired
46+
static void completion_bridge_inner(const char *buf, linenoiseCompletions *lc)
47+
{
48+
CAMLparam0();
49+
CAMLlocal1(str_copy);
50+
str_copy = caml_copy_string(buf);
51+
caml_callback2(*caml_named_value("lnoise_completion_cb"), str_copy, (value)lc);
52+
CAMLreturn0;
53+
}
54+
4555
static void completion_bridge(const char *buf, linenoiseCompletions *lc)
4656
{
4757
caml_acquire_runtime_system();
48-
value str_copy = caml_copy_string(buf);
49-
caml_callback2(*caml_named_value("lnoise_completion_cb"), str_copy, (value)lc);
58+
completion_bridge_inner(buf, lc);
5059
caml_release_runtime_system();
5160
}
5261

0 commit comments

Comments
 (0)