diff mbox series

[v4,11/11] tools/ocaml/libs/xb: drop Xs_ring.write

Message ID ce0700a52e79eaa265f7044007d469369cacf4fe.1671214525.git.edwin.torok@cloud.com (mailing list archive)
State New, archived
Headers show
Series OCaml fixes | expand

Commit Message

Edwin Török Dec. 16, 2022, 6:25 p.m. UTC
Unused, only Xs_ring.write_substring is used.
Also the bytes/string conversion here is backwards: the C stub implements the
bytes version and then we use a Bytes.unsafe_of_string to convert a string into
bytes.

However the operation here really is read-only: we read from the string and
write it to the ring, so the C stub should implement the read-only string
version, and if needed we could use Bytes.unsafe_to_string to be able to send
'bytes'. However that is not necessary as the 'bytes' version is dropped above.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
---
Changes:
* new patch
---
 tools/ocaml/libs/xb/xs_ring.ml      | 5 +----
 tools/ocaml/libs/xb/xs_ring_stubs.c | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/tools/ocaml/libs/xb/xs_ring.ml b/tools/ocaml/libs/xb/xs_ring.ml
index 2a27aa56c2..87c6b243e4 100644
--- a/tools/ocaml/libs/xb/xs_ring.ml
+++ b/tools/ocaml/libs/xb/xs_ring.ml
@@ -25,14 +25,11 @@  module Server_features = Set.Make(struct
   end)
 
 external read: Xenmmap.mmap_interface -> bytes -> int -> int = "ml_interface_read"
-external write: Xenmmap.mmap_interface -> bytes -> int -> int = "ml_interface_write"
+external write_substring: Xenmmap.mmap_interface -> string -> int -> int = "ml_interface_write"
 
 external _internal_set_server_features: Xenmmap.mmap_interface -> int -> unit = "ml_interface_set_server_features" [@@noalloc]
 external _internal_get_server_features: Xenmmap.mmap_interface -> int = "ml_interface_get_server_features" [@@noalloc]
 
-let write_substring mmap buff len =
-  write mmap (Bytes.unsafe_of_string buff) len
-
 let get_server_features mmap =
   (* NB only one feature currently defined above *)
   let x = _internal_get_server_features mmap in
diff --git a/tools/ocaml/libs/xb/xs_ring_stubs.c b/tools/ocaml/libs/xb/xs_ring_stubs.c
index 28c79ee139..dca6059b0d 100644
--- a/tools/ocaml/libs/xb/xs_ring_stubs.c
+++ b/tools/ocaml/libs/xb/xs_ring_stubs.c
@@ -119,7 +119,7 @@  CAMLprim value ml_interface_write(value ml_interface,
     CAMLlocal1(ml_result);
 
     struct mmap_interface *interface = GET_C_STRUCT(ml_interface);
-    const unsigned char *buffer = Bytes_val(ml_buffer);
+    const char *buffer = String_val(ml_buffer);
     int len = Int_val(ml_len);
     int result;