let write con s len =
match con.backend with
- | Fd backfd -> write_fd backfd con (Bytes.of_string s) len
+ (* we can use unsafe_of_string here as the bytes are used immutably
+ in the Unix.write operation. *)
+ | Fd backfd -> write_fd backfd con (Bytes.unsafe_of_string s) len
| Xenmmap backmmap -> write_mmap backmmap con s len
(* NB: can throw Reconnect *)
Bytes.blit_string line 0 dst_line 0 (len - 2);
Bytes.set dst_line (len-2) '.';
Bytes.set dst_line (len-1) '.';
- Bytes.to_string dst_line
+ Bytes.unsafe_to_string dst_line
else line
let log_rotate ref_ch log_file log_nb_files =
if Bytes.get data i = '\000' then
Bytes.set data i ' '
done;
- String.escaped (Bytes.to_string data)
+ String.escaped (Bytes.unsafe_to_string data)
let activate_access_log = ref true
let access_log_destination = ref (File (Paths.xen_log_dir ^ "/xenstored-access.log"))
let date = string_of_date() in
let tid = string_of_tid ~con tid in
let access_type = string_of_access_type access_type in
- let data = sanitize_data (Bytes.of_string data) in
+ (* we can use unsafe_of_string here as the sanitize_data function
+ immediately makes a copy of the data and operates on that. *)
+ let data = sanitize_data (Bytes.unsafe_of_string data) in
let prefix = prefix !access_log_destination date in
let msg = Printf.sprintf "%s %s %s %s" prefix tid access_type data in
logger.write ~level msg)
let pid = Unix.getpid () in
let buf = string_of_int pid ^ "\n" in
let len = String.length buf in
- if Unix.write fd (Bytes.of_string buf) 0 len <> len
+ if Unix.write fd (Bytes.unsafe_of_string buf) 0 len <> len
then failwith "pidfile_write failed";
)
(fun () -> Unix.close fd)
Bytes.set hs (i * 2) seq.[0];
Bytes.set hs (i * 2 + 1) seq.[1];
done;
- Bytes.to_string hs
+ Bytes.unsafe_to_string hs
let unhexify hs =
let char_of_hexseq seq0 seq1 = Char.chr (int_of_string (sprintf "0x%c%c" seq0 seq1)) in
do
Bytes.set b i (char_of_hexseq hs.[i * 2] hs.[i * 2 + 1])
done;
- Bytes.to_string b
+ Bytes.unsafe_to_string b
let trim_path path =
try
let buf = Bytes.make 20 (char_of_int 0) in
let sz = Unix.read fd buf 0 20 in
Unix.close fd;
- int_of_string (Bytes.to_string (Bytes.sub buf 0 sz))
+ int_of_string (Bytes.sub_string buf 0 sz)
let path_complete path connection_path =
if String.get path 0 <> '/' then