Skip to content

Commit

Permalink
another round of memory safety
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Mar 7, 2024
1 parent 150271f commit bfd47a8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/linenoise_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,33 @@ static void completion_bridge(const char *buf, linenoiseCompletions *lc)
caml_release_runtime_system();
}

static char *hints_bridge(const char *buf, int *color, int *bold)
static char *hints_bridge_inner(const char *buf, int *color, int *bold)
{
caml_acquire_runtime_system();
CAMLparam0();
CAMLlocal2(str_copy, cb_result);

str_copy = caml_copy_string(buf);

cb_result = caml_callback(*caml_named_value("lnoise_hints_cb"), str_copy);
if (cb_result == Val_none) {
caml_release_runtime_system();
CAMLreturnT(char *,NULL);
} else {
char* msg = caml_stat_strdup(String_val(Field(Field(cb_result, 0), 0)));
*color = Int_val(Field(Field(cb_result, 0), 1)) + 31;
*bold = Bool_val(Field(Field(cb_result, 0), 2));
caml_release_runtime_system();
CAMLreturnT(char *,msg);
}
}

static char *hints_bridge(const char *buf, int *color, int *bold)
{
caml_acquire_runtime_system();
char* res = hints_bridge_inner(buf, color, bold);
caml_release_runtime_system();
return res;
}


static void free_hints_bridge(void* data) {
caml_acquire_runtime_system();
caml_stat_free(data);
Expand Down

0 comments on commit bfd47a8

Please sign in to comment.