From 150271f63fb9f8c7f124d0602f5d12608e9829db Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 7 Mar 2024 14:50:36 -0500 Subject: [PATCH] declare local OCaml value to the GC in completion bridge --- src/linenoise_stubs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/linenoise_stubs.c b/src/linenoise_stubs.c index bd8bdb6..28d2bbc 100644 --- a/src/linenoise_stubs.c +++ b/src/linenoise_stubs.c @@ -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(); }