Thank you for the reply.
Does caml_string_length(s) includes the null end? That is, I’m having the following code converting the result, am I doing this right?
From caml_string_is_c_safe I’d assume caml_string_length(s) does not count the null byte.
static char **command_completion(const char *text, int start, int end) {
char **matches = NULL;
value words;
/* disable file pathname completion */
rl_attempted_completion_over = 1;
if(start == 0) {
words = caml_callback(*command_callback_f, caml_copy_string(text));
int n = Wosize_val(words);
if (n == 0) return(matches);
matches = malloc((1 + n) * sizeof(char*));
if (matches == NULL) return(matches);
int i;
for (i = 0; i < n; ++i) {
value s = Field(words, i);
char *cs = malloc(caml_string_length(s));
matches[i] = strcpy(cs, String_val(s));
}
matches[n] = NULL;
}
return(matches);
}