xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Michael Young <m.a.young@durham.ac.uk>
To: Wei Liu <wei.liu2@citrix.com>
Cc: Marcello Seri <marcello.seri@citrix.com>,
	xen-devel@lists.xenproject.org,
	Christian Lindig <christian.lindig@citrix.com>,
	John Thomson <git@johnthomson.fastmail.com.au>,
	David Scott <dave@recoil.org>
Subject: Re: [PATCH 1/2] make xen ocaml safe-strings compliant
Date: Tue, 6 Feb 2018 21:56:14 +0000 (GMT)	[thread overview]
Message-ID: <alpine.LFD.2.21.1802062144430.3326@austen3.home> (raw)
In-Reply-To: <20180206164930.hall3jh62vn4vrix@citrix.com>

[-- Attachment #1: Type: text/plain, Size: 990 bytes --]

On Tue, 6 Feb 2018, Wei Liu wrote:

> On Tue, Jan 30, 2018 at 10:55:47PM +0000, Michael Young wrote:
>> Xen built with ocaml 4.06 gives errors such as
>> Error: This expression has type bytes but an expression was
>> 	expected of type string
>> as Byte and safe-strings which were introduced in 4.02 are the
>> default in 4.06.
>> This patch which is partly by Richard W.M. Jones of Red Hat
>> from https://bugzilla.redhat.com/show_bug.cgi?id=1526703
>> fixes these issues.
>>
>> Signed-off-by: Michael Young <m.a.young@durham.ac.uk>
>> Reviewed-by: Christian Lindig <christian.lindig@citrix.com>
>
> Strangely this doesn't apply to staging. And after examining the
> downloaded patch I'm not sure if my mail client is acting up. Do you
> have a git branch that I can pull from?

The patch needed to be reduced as one of the sections being patched was 
removed by a recent patch. I am attaching the revised patch as a file 
in case there was also an email formatting issue.

 	Michael Young

[-- Attachment #2: Type: text/plain, Size: 6150 bytes --]

From 247cea9b587baafaf80bcc5b44bc68defb4efa26 Mon Sep 17 00:00:00 2001
From: Michael Young <m.a.young@durham.ac.uk>
Date: Tue, 6 Feb 2018 21:27:23 +0000
Subject: [PATCH 1/2 v2] make xen ocaml safe-strings compliant

Xen built with ocaml 4.06 gives errors such as
Error: This expression has type bytes but an expression was
        expected of type string
as Byte and safe-strings which were introduced in 4.02 are the
default in 4.06.
This patch which is mostly by Richard W.M. Jones of Red Hat
from https://bugzilla.redhat.com/show_bug.cgi?id=1526703
fixes these issues.

v2: drop tools/ocaml/libs/xc/xenctrl.ml from the patch as the
affected code was removed by commit d933f1a53c06002351c1e36d40615e40bd4bf6af
tools/ocaml: Drop coredump infrastructure

Signed-off-by: Michael Young <m.a.young@durham.ac.uk>
Reviewed-by: Christian Lindig <christian.lindig@citrix.com>
---
 tools/ocaml/libs/xb/xb.ml        |  6 +++---
 tools/ocaml/xenstored/logging.ml | 22 +++++++++++-----------
 tools/ocaml/xenstored/stdext.ml  |  2 +-
 tools/ocaml/xenstored/utils.ml   | 18 +++++++++---------
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/tools/ocaml/libs/xb/xb.ml b/tools/ocaml/libs/xb/xb.ml
index 50944b5fd6..aa2cf98223 100644
--- a/tools/ocaml/libs/xb/xb.ml
+++ b/tools/ocaml/libs/xb/xb.ml
@@ -84,7 +84,7 @@ let read_mmap back con s len =
 
 let read con s len =
 	match con.backend with
-	| Fd backfd     -> read_fd backfd con s len
+	| Fd backfd     -> read_fd backfd con (Bytes.of_string s) len
 	| Xenmmap backmmap -> read_mmap backmmap con s len
 
 let write_fd back con s len =
@@ -98,7 +98,7 @@ let write_mmap back con s len =
 
 let write con s len =
 	match con.backend with
-	| Fd backfd     -> write_fd backfd con s len
+	| Fd backfd     -> write_fd backfd con (Bytes.of_string s) len
 	| Xenmmap backmmap -> write_mmap backmmap con s len
 
 (* NB: can throw Reconnect *)
@@ -147,7 +147,7 @@ let input con =
 	| NoHdr (i, buf)      ->
 		(* we complete the partial header *)
 		if sz > 0 then
-			String.blit s 0 buf (Partial.header_size () - i) sz;
+			String.blit s 0 (Bytes.of_string buf) (Partial.header_size () - i) sz;
 		con.partial_in <- if sz = i then
 			HaveHdr (Partial.of_string buf) else NoHdr (i - sz, buf)
 	);
diff --git a/tools/ocaml/xenstored/logging.ml b/tools/ocaml/xenstored/logging.ml
index 0c0d03d0c4..d24abf8a3a 100644
--- a/tools/ocaml/xenstored/logging.ml
+++ b/tools/ocaml/xenstored/logging.ml
@@ -60,11 +60,11 @@ type logger =
 let truncate_line nb_chars line = 
 	if String.length line > nb_chars - 1 then
 		let len = max (nb_chars - 1) 2 in
-		let dst_line = String.create len in
-		String.blit line 0 dst_line 0 (len - 2);
-		dst_line.[len-2] <- '.'; 
-		dst_line.[len-1] <- '.';
-		dst_line
+		let dst_line = Bytes.create len in
+		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
 	else line
 
 let log_rotate ref_ch log_file log_nb_files =
@@ -252,13 +252,13 @@ let string_of_access_type = function
 	*)
 
 let sanitize_data data =
-	let data = String.copy data in
-	for i = 0 to String.length data - 1
+	let data = Bytes.copy data in
+	for i = 0 to Bytes.length data - 1
 	do
-		if data.[i] = '\000' then
-			data.[i] <- ' '
+		if Bytes.get data i = '\000' then
+			Bytes.set data i ' '
 	done;
-	String.escaped data
+	String.escaped (Bytes.to_string data)
 
 let activate_access_log = ref true
 let access_log_destination = ref (File (Paths.xen_log_dir ^ "/xenstored-access.log"))
@@ -291,7 +291,7 @@ let access_logging ~con ~tid ?(data="") ~level access_type =
 				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 data in
+				let data = sanitize_data (Bytes.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)
diff --git a/tools/ocaml/xenstored/stdext.ml b/tools/ocaml/xenstored/stdext.ml
index b8a8fd00e1..d05155c97e 100644
--- a/tools/ocaml/xenstored/stdext.ml
+++ b/tools/ocaml/xenstored/stdext.ml
@@ -122,7 +122,7 @@ let pidfile_write filename =
 		let pid = Unix.getpid () in
 		let buf = string_of_int pid ^ "\n" in
 		let len = String.length buf in
-		if Unix.write fd buf 0 len <> len 
+		if Unix.write fd (Bytes.of_string buf) 0 len <> len 
 		then failwith "pidfile_write failed";
 	)
 	(fun () -> Unix.close fd)
diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml
index e89c1aff04..c96def7bee 100644
--- a/tools/ocaml/xenstored/utils.ml
+++ b/tools/ocaml/xenstored/utils.ml
@@ -45,23 +45,23 @@ let get_hierarchy path =
 
 let hexify s =
 	let hexseq_of_char c = sprintf "%02x" (Char.code c) in
-	let hs = String.create (String.length s * 2) in
+	let hs = Bytes.create (String.length s * 2) in
 	for i = 0 to String.length s - 1
 	do
 		let seq = hexseq_of_char s.[i] in
-		hs.[i * 2] <- seq.[0];
-		hs.[i * 2 + 1] <- seq.[1];
+		Bytes.set hs (i * 2) seq.[0];
+		Bytes.set hs (i * 2 + 1) seq.[1];
 	done;
-	hs
+	Bytes.to_string hs
 
 let unhexify hs =
 	let char_of_hexseq seq0 seq1 = Char.chr (int_of_string (sprintf "0x%c%c" seq0 seq1)) in
-	let s = String.create (String.length hs / 2) in
-	for i = 0 to String.length s - 1
+	let s = Bytes.create (String.length hs / 2) in
+	for i = 0 to Bytes.length s - 1
 	do
-		s.[i] <- char_of_hexseq hs.[i * 2] hs.[i * 2 + 1]
+		Bytes.set s i (char_of_hexseq hs.[i * 2] hs.[i * 2 + 1])
 	done;
-	s
+	Bytes.to_string s
 
 let trim_path path =
 	try
@@ -85,7 +85,7 @@ let create_unix_socket name =
 let read_file_single_integer filename =
 	let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o640 in
 	let buf = String.make 20 (char_of_int 0) in
-	let sz = Unix.read fd buf 0 20 in
+	let sz = Unix.read fd (Bytes.of_string buf) 0 20 in
 	Unix.close fd;
 	int_of_string (String.sub buf 0 sz)
 
-- 
2.14.3


[-- Attachment #3: Type: text/plain, Size: 157 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-02-06 21:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30 22:55 [PATCH 1/2] make xen ocaml safe-strings compliant Michael Young
2018-02-06 16:49 ` Wei Liu
2018-02-06 21:56   ` Michael Young [this message]
2018-02-07 10:31     ` Wei Liu
2018-02-08 17:49 ` Dario Faggioli
2018-02-08 18:03   ` Wei Liu
2018-02-08 18:24     ` Wei Liu
2018-02-09  9:20       ` Christian Lindig
2018-02-09 10:06         ` Dario Faggioli
2018-02-12 14:55         ` Wei Liu
2018-03-09 22:57           ` Michael Young
2018-03-09 23:47             ` Christian Lindig
2018-03-10  0:36               ` Michael Young
2018-03-12 11:29             ` Christian Lindig
2018-03-12 19:35               ` Michael Young
2018-03-13  9:29                 ` Christian Lindig
2018-03-13 14:49                   ` Wei Liu
2018-02-13  0:35         ` Michael Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.21.1802062144430.3326@austen3.home \
    --to=m.a.young@durham.ac.uk \
    --cc=christian.lindig@citrix.com \
    --cc=dave@recoil.org \
    --cc=git@johnthomson.fastmail.com.au \
    --cc=marcello.seri@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).