tools/ocaml: libxb: Avoid to use String_val() when value is bytes
authorJulien Grall <jgrall@amazon.com>
Mon, 30 Mar 2020 17:50:08 +0000 (18:50 +0100)
committerJulien Grall <jgrall@amazon.com>
Mon, 20 Apr 2020 14:03:07 +0000 (15:03 +0100)
commit78686437e949a85a207ae1a0d637efe2d3778bbe
treeff7374c9fc5f8a669d6edbadb6300981cc3af5cd
parentd92ba1aa7cf877a77abdcbd94a6a19fc55886a75
tools/ocaml: libxb: Avoid to use String_val() when value is bytes

Commit ec7d54dd1a "ocaml/libs/xb: Use bytes in place of strings for
mutable buffers" switch mutable buffers from string to bytes. However
the C code were still using String_Val() to access them.

While the underlying structure is the same between string and bytes, a
string is meant to be immutable. OCaml 4.06.1 and later will enforce it.
Therefore, it will not be possible to build the OCaml libs when using
-safe-string. This is because String_val() will return a const value.

To avoid plain cast in the code, the code is now switched to use
Bytes_val(). As the macro is not defined in older OCaml version, we need
to provide a stub.

Take the opportunity to switch to const the buffer in
ml_interface_write() as it should not be modified.

Reported-by: Dario Faggioli <dfaggioli@suse.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/xb/xs_ring_stubs.c