Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for OCaml 4.06.0 (-safe-string is the default) #38

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5080,7 +5080,7 @@ let loadBinaryFile (filename : string) : file =
(* Take the name of a file and make a valid symbol name out of it. There are
* a few characters that are not valid in symbols *)
let makeValidSymbolName (s: string) =
let s = String.copy s in (* So that we can update in place *)
let b = Bytes.copy (Bytes.of_string s) in (* So that we can update in place *)
let l = String.length s in
for i = 0 to l - 1 do
let c = String.get s i in
Expand All @@ -5090,9 +5090,9 @@ let makeValidSymbolName (s: string) =
| _ -> false
in
if isinvalid then
String.set s i '_';
Bytes.set b i '_';
done;
s
Bytes.to_string b

let rec addOffset (toadd: offset) (off: offset) : offset =
match off with
Expand Down
6 changes: 3 additions & 3 deletions src/formatlex.mll
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ let scan_oct_escape str =
* We convert L"Hi" to "H\000i\000" *)
let wbtowc wstr =
let len = String.length wstr in
let dest = String.make (len * 2) '\000' in
let dest = Bytes.make (len * 2) '\000' in
for i = 0 to len-1 do
dest.[i*2] <- wstr.[i] ;
Bytes.set dest (i*2) (String.get wstr i)
done ;
dest
Bytes.to_string dest

(* This function converst the "Hi" in L"Hi" to { L'H', L'i', L'\0' } *)
let wstr_to_warray wstr =
Expand Down
11 changes: 6 additions & 5 deletions src/ocamlutil/errormsg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,17 @@ let cleanFileName str =
if str <> "" && String.get str 0 = '"' (* '"' ( *)
then rem_quotes str else str in
let l = String.length str1 in
let str1 = Bytes.of_string str1 in
let rec loop (copyto: int) (i: int) =
if i >= l then
String.sub str1 0 copyto
Bytes.to_string (Bytes.sub str1 0 copyto)
else
let c = String.get str1 i in
let c = Bytes.get str1 i in
if c <> '\\' then begin
String.set str1 copyto c; loop (copyto + 1) (i + 1)
Bytes.set str1 copyto c; loop (copyto + 1) (i + 1)
end else begin
String.set str1 copyto '/';
if i < l - 2 && String.get str1 (i + 1) = '\\' then
Bytes.set str1 copyto '/';
if i < l - 2 && Bytes.get str1 (i + 1) = '\\' then
loop (copyto + 1) (i + 2)
else
loop (copyto + 1) (i + 1)
Expand Down
18 changes: 9 additions & 9 deletions src/ocamlutil/pretty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -725,31 +725,31 @@ let gprintf (finish : doc -> 'b)
invalid_arg ("dprintf: unimplemented format "
^ (String.sub format i (j-i+1)));
let j' = succ j in (* eat the d,i,x etc. *)
let format_spec = "% " in
String.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
let format_spec = Bytes.of_string "% " in
Bytes.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
Obj.magic(fun n ->
collect (dctext1 acc
(Int64.format format_spec n))
(Int64.format (Bytes.to_string format_spec) n))
(succ j'))
| 'l' ->
if j != i + 1 then invalid_arg ("dprintf: unimplemented format "
^ (String.sub format i (j-i+1)));
let j' = succ j in (* eat the d,i,x etc. *)
let format_spec = "% " in
String.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
let format_spec = Bytes.of_string "% " in
Bytes.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
Obj.magic(fun n ->
collect (dctext1 acc
(Int32.format format_spec n))
(Int32.format (Bytes.to_string format_spec) n))
(succ j'))
| 'n' ->
if j != i + 1 then invalid_arg ("dprintf: unimplemented format "
^ (String.sub format i (j-i+1)));
let j' = succ j in (* eat the d,i,x etc. *)
let format_spec = "% " in
String.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
let format_spec = Bytes.of_string "% " in
Bytes.set format_spec 1 (fget j'); (* format_spec = "%x", etc. *)
Obj.magic(fun n ->
collect (dctext1 acc
(Nativeint.format format_spec n))
(Nativeint.format (Bytes.to_string format_spec) n))
(succ j'))
| 'f' | 'e' | 'E' | 'g' | 'G' ->
Obj.magic(fun f ->
Expand Down