While reviewing my C interface stuff, I noticed a function caml_modify()
Otherwise, you are updating a field that previously contained a well-formed value; then, call the caml_modify function:
caml_modify(&Field(v, n), w);
… and goes on to show it used that way, while making a list. Which I noticed because in fact I do build a list, but I don’t modify a block field. It happens in a loop, as seemed to me the obvious way -
CAMLlocal3(tl, hd, mval);
tl = Val_int(0);
int i;
for (i = count - 1; i >= 0; --i) {
int32 ival;
... // ival to be cons'd to list
hd = caml_alloc(2, 0);
mval = Val_int(ival);
Store_field(hd, 0, mval);
Store_field(hd, 1, tl);
tl = hd; // <--- oops? should be caml_modify(&tl, hd); ??
}
So I just tried it, and it seems to be an improvement. If I’m right, maybe caml_modify()
warrants more than incidental mention in the C interface documentation.