From 2a66e9d057bee3f0afddcdcfe3be3996b8adf65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 27 Sep 2022 12:20:36 +0200 Subject: [PATCH] Adapt to OCaml changes --- Makefile | 2 +- README.txt | 5 ++-- database/column.ml | 25 ++++++++-------- database/rtree.ml | 2 +- database/table.ml | 6 ++-- generic/bitvect.ml | 8 +++--- generic/bytearray.ml | 20 +++++-------- generic/bytearray.mli | 2 -- generic/bytearray_stubs.c | 4 +-- generic/mapped_file.ml | 15 ++++++---- generic/protobuf.ml | 6 ++-- generic/task.ml | 18 ++++++------ generic/util.ml | 60 +++++++++++++++++++-------------------- generic/util.mli | 2 +- osm/coastline.ml | 11 ++++--- osm/highway.ml | 8 +++--- osm/lib/osm_display.ml | 21 +++++++------- osm/parser.ml | 16 +++++------ osm/surfaces.ml | 14 ++++----- 19 files changed, 122 insertions(+), 123 deletions(-) diff --git a/Makefile b/Makefile index d90da2d..6103ca2 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ OCAMLLEX=ocamllex OCAMLYACC=ocamlyacc -v OCAMLDEP=ocamldep -OPTCOMPFLAGS =-package zip,bigarray,unix,cairo2.lablgtk2 -inline 3 -g \ +OPTCOMPFLAGS =-package zip,bigarray,unix,cairo2-gtk -inline 3 -g \ $(DIRS) COMPFLAGS = $(DIRS) DEPFLAGS= $(DIRS) diff --git a/README.txt b/README.txt index 13907d5..3a1107a 100644 --- a/README.txt +++ b/README.txt @@ -5,7 +5,7 @@ This software only works on 64-bit machines. The following external libraries are needed: camlzip, cairo, lablgtk. They can be install through opam: - opam install camlzip cairo2 lablgtk + opam install camlzip cairo2-gtk To compile, just type 'make'. @@ -102,9 +102,8 @@ to display the map: Optionally, you can include the coastline data: - download coastlines-split-4326.zip from - http://openstreetmapdata.com/data/coastlines + https://osmdata.openstreetmap.de/data/coastlines.html (shapefile format, containing linestrings in WGS84 projection) -- unzip the file - build the coastline R-trees: ./coastline /path/to/coastlines-split-4326.zip diff --git a/database/column.ml b/database/column.ml index e9eafd6..c6d8bbc 100644 --- a/database/column.ml +++ b/database/column.ml @@ -342,7 +342,7 @@ module Output_stream_write = struct type output_stream = { fd : Unix.file_descr; mutable pos : int; - write_buffer : string; + write_buffer : bytes; mutable buf_pos : int; buffer : int array; mutable i : int; @@ -357,7 +357,7 @@ module Output_stream_write = struct Unix.openfile nm [Unix.O_RDWR; Unix.O_CREAT; Unix.O_TRUNC] 0o666 in if temp <> None then Unix.unlink nm; ignore (Unix.lseek fd 24 Unix.SEEK_SET); - { fd = fd; write_buffer = String.create (write_size + max_overhead); + { fd = fd; write_buffer = Bytes.create (write_size + max_overhead); buffer = Array.make block_size 0; table = [||]; pos = 24; buf_pos = 0; i = 0; n = 0 } @@ -372,11 +372,12 @@ module Output_stream_write = struct end; s.table.(s.n - 1) <- s.pos - external encode_chunk : string -> int -> int array -> int -> int -> int + external encode_chunk : bytes -> int -> int array -> int -> int -> int = "encode_chunk_to_string_ml" let write_int_2 a p v = - a.[p] <- Char.chr (v land 0xff); a.[p + 1] <- Char.chr ((v lsr 8) land 0xff) + Bytes.set a p (Char.chr (v land 0xff)); + Bytes.set a (p + 1) (Char.chr ((v lsr 8) land 0xff)) let write_int_8 a p v = let v = ref v in @@ -394,7 +395,7 @@ module Output_stream_write = struct let len = min write_size s.buf_pos in really_write s.fd s.write_buffer 0 len; if len < s.buf_pos then - String.blit s.write_buffer len s.write_buffer 0 (s.buf_pos - len); + Bytes.blit s.write_buffer len s.write_buffer 0 (s.buf_pos - len); s.buf_pos <- s.buf_pos - len let flush_buffer s = @@ -433,19 +434,19 @@ module Output_stream_write = struct if i > 0 then flush_buffer s; write_buffer s; assert (s.buf_pos = 0); - let a = String.create (8 * s.n) in + let a = Bytes.create (8 * s.n) in for j = 0 to s.n - 1 do write_int_8 a (8 * j) s.table.(j) done; assert (Unix.lseek s.fd 0 Unix.SEEK_CUR = s.pos); - really_write s.fd a 0 (String.length a); + really_write s.fd a 0 (Bytes.length a); let len = (s.n - 1) * block_size + (if i = 0 then block_size else i) in - let a = magic ^ String.create 16 in + let a = Bytes.cat (Bytes.of_string magic) (Bytes.create 16) in write_int_8 a 8 len; write_int_8 a 16 s.pos; ignore (Unix.lseek s.fd 0 Unix.SEEK_SET); - really_write s.fd a 0 (String.length a) + really_write s.fd a 0 (Bytes.length a) let close_out s = finish_output s; @@ -648,8 +649,8 @@ let with_spec_2 f nm1 nm2 = (****) let is_column nm = - let ch = Pervasives.open_in (file_in_database nm) in - let s = String.make 8 ' ' in + let ch = Stdlib.open_in (file_in_database nm) in + let s = Bytes.make 8 ' ' in ignore (input ch s 0 8); close_in ch; - s = magic + Bytes.unsafe_to_string s = magic diff --git a/database/rtree.ml b/database/rtree.ml index 0e7c050..d5c5cf0 100644 --- a/database/rtree.ml +++ b/database/rtree.ml @@ -63,7 +63,7 @@ end type level = { mutable level_bbox : Bbox.t; - buffer : string; + buffer : bytes; file : (int32, Bigarray.int32_elt) Mapped_file.output_stream; mutable idx : int } diff --git a/database/table.ml b/database/table.ml index 442bbb4..a9ceaea 100644 --- a/database/table.ml +++ b/database/table.ml @@ -32,7 +32,8 @@ let make ?len nm kind = let ch = Unix.openfile nm flags 0o600 in let l = match len with None -> map_incr | Some l -> l in { ch = ch; - ar = Bigarray.Array1.map_file ch kind Bigarray.c_layout true l } + ar = Bigarray.array1_of_genarray + (Unix.map_file ch kind Bigarray.c_layout true [|l|]) } let extend a l = let l' = ref (Bigarray.Array1.dim a.ar) in @@ -41,7 +42,8 @@ Format.printf "RESIZE@."; while !l' < l do l' := !l' + map_incr done; let kind = Bigarray.Array1.kind a.ar in let layout = Bigarray.Array1.layout a.ar in - a.ar <- Bigarray.Array1.map_file a.ch kind layout true !l' + a.ar <- Bigarray.array1_of_genarray + (Unix.map_file a.ch kind layout true [|!l'|]) end (****) diff --git a/generic/bitvect.ml b/generic/bitvect.ml index 89363a1..9d534e6 100644 --- a/generic/bitvect.ml +++ b/generic/bitvect.ml @@ -16,14 +16,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type t = string +type t = bytes -let make n = String.make ((n + 7) lsr 3) '\000' +let make n = Bytes.make ((n + 7) lsr 3) '\000' let set v i = let j = i lsr 3 in - v.[j] <- Char.chr (Char.code v.[j] lor (1 lsl (i land 7))) + Bytes.set v j (Char.chr (Char.code (Bytes.get v j) lor (1 lsl (i land 7)))) let test v i = let j = i lsr 3 in - Char.code v.[j] land (1 lsl (i land 7)) <> 0 + Char.code (Bytes.get v j) land (1 lsl (i land 7)) <> 0 diff --git a/generic/bytearray.ml b/generic/bytearray.ml index e0b3b1f..4454332 100644 --- a/generic/bytearray.ml +++ b/generic/bytearray.ml @@ -37,17 +37,17 @@ let unsafe_blit_to_string a i s j l = *) external unsafe_blit_from_string : string -> int -> t -> int -> int -> unit - = "ml_blit_string_to_bigarray" "noalloc" + = "ml_blit_string_to_bigarray" [@@noalloc] -external unsafe_blit_to_string : t -> int -> string -> int -> int -> unit - = "ml_blit_bigarray_to_string" "noalloc" +external unsafe_blit_to_string : t -> int -> bytes -> int -> int -> unit + = "ml_blit_bigarray_to_string" [@@noalloc] let to_string a = let l = length a in if l > Sys.max_string_length then invalid_arg "Bytearray.to_string" else - let s = String.create l in + let s = Bytes.create l in unsafe_blit_to_string a 0 s 0 l; - s + Bytes.unsafe_to_string s let of_string s = let l = String.length s in @@ -61,9 +61,9 @@ let sub a ofs len = then invalid_arg "Bytearray.sub" else begin - let s = String.create len in + let s = Bytes.create len in unsafe_blit_to_string a ofs s 0 len; - s + Bytes.unsafe_to_string s end let rec prefix_rec a i a' i' l = @@ -82,12 +82,6 @@ let blit_from_string s i a j l = then invalid_arg "Bytearray.blit_from_string" else unsafe_blit_from_string s i a j l -let blit_to_string a i s j l = - if l < 0 || i < 0 || i > length a - l - || j < 0 || j > String.length s - l - then invalid_arg "Bytearray.blit_to_string" - else unsafe_blit_to_string a i s j l - external marshal : 'a -> Marshal.extern_flags list -> t = "ml_marshal_to_bigarray" diff --git a/generic/bytearray.mli b/generic/bytearray.mli index 796f6fa..fa697f9 100644 --- a/generic/bytearray.mli +++ b/generic/bytearray.mli @@ -31,8 +31,6 @@ val sub : t -> int -> int -> string val blit_from_string : string -> int -> t -> int -> int -> unit -val blit_to_string : t -> int -> string -> int -> int -> unit - val prefix : t -> t -> int -> bool val marshal : 'a -> Marshal.extern_flags list -> t diff --git a/generic/bytearray_stubs.c b/generic/bytearray_stubs.c index e4abf8b..6d55c1b 100644 --- a/generic/bytearray_stubs.c +++ b/generic/bytearray_stubs.c @@ -51,7 +51,7 @@ CAMLprim value ml_unmarshal_from_bigarray(value b, value ofs) CAMLprim value ml_blit_string_to_bigarray (value s, value i, value a, value j, value l) { - char *src = String_val(s) + Int_val(i); + const char *src = String_val(s) + Int_val(i); char *dest = Array_data(Bigarray_val(a), j); memcpy(dest, src, Long_val(l)); return Val_unit; @@ -61,7 +61,7 @@ CAMLprim value ml_blit_bigarray_to_string (value a, value i, value s, value j, value l) { char *src = Array_data(Bigarray_val(a), i); - char *dest = String_val(s) + Long_val(j); + char *dest = Bytes_val(s) + Long_val(j); memcpy(dest, src, Long_val(l)); return Val_unit; } diff --git a/generic/mapped_file.ml b/generic/mapped_file.ml index 2451fe9..ef0446f 100644 --- a/generic/mapped_file.ml +++ b/generic/mapped_file.ml @@ -88,7 +88,8 @@ let open_out nm ?temp map_incr (kind, element_size) = let ch = Unix.openfile nm flags 0o600 in if temp then Unix.unlink nm; { ch = ch; map_incr = map_incr; len = 0; - ar = Bigarray.Array1.map_file ch kind Bigarray.c_layout true map_incr; + ar = Bigarray.array1_of_genarray + (Unix.map_file ch kind Bigarray.c_layout true [|map_incr|]); element_size = element_size } let resize s l = @@ -97,7 +98,8 @@ let resize s l = if !l' < l then begin while !l' < l do l' := !l' + s.map_incr done; let kind = Bigarray.Array1.kind s.ar in - s.ar <- Bigarray.Array1.map_file s.ch kind Bigarray.c_layout true !l' + s.ar <- Bigarray.array1_of_genarray + (Unix.map_file s.ch kind Bigarray.c_layout true [|!l'|]) end let output_array s = s.ar @@ -111,12 +113,14 @@ type ('a, 'b) t = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t let open_in nm kind = let flags = [Unix.O_RDWR] in let ch = Unix.openfile nm flags 0o600 in - let a = Bigarray.Array1.map_file ch kind Bigarray.c_layout true (-1) in + let a = Bigarray.array1_of_genarray + (Unix.map_file ch kind Bigarray.c_layout true [|-1|]) in Unix.close ch; a let open_in_fd ch kind = - let a = Bigarray.Array1.map_file ch kind Bigarray.c_layout true (-1) in + let a = Bigarray.array1_of_genarray + (Unix.map_file ch kind Bigarray.c_layout true [|-1|]) in Unix.close ch; a @@ -125,6 +129,7 @@ let array a = a let freeze s = Unix.ftruncate s.ch s.len; let kind = Bigarray.Array1.kind s.ar in - let a = Bigarray.Array1.map_file s.ch kind Bigarray.c_layout true (-1) in + let a = Bigarray.array1_of_genarray + (Unix.map_file s.ch kind Bigarray.c_layout true [|-1|]) in Unix.close s.ch; a diff --git a/generic/protobuf.ml b/generic/protobuf.ml index 37977b8..e72b389 100644 --- a/generic/protobuf.ml +++ b/generic/protobuf.ml @@ -50,12 +50,10 @@ let buffer_copy b = {s = b.s; i = b.i; l = b.l} let empty_buffer = {s =""; i = 0; l = 0} let input_string ch l = - let s = String.create l in - really_input ch s 0 l; - s + really_input_string ch l let buffer_from_channel ch l = - buffer_from_substring (input_string ch l) 0 l + buffer_from_substring (really_input_string ch l) 0 l let chunk buf l = let i = buf.i in diff --git a/generic/task.ml b/generic/task.ml index 6e2c4d7..9fe195e 100644 --- a/generic/task.ml +++ b/generic/task.ml @@ -62,13 +62,13 @@ let functions = Hashtbl.create 17 let send pipe i l = let s = Printf.sprintf "%d %d\n" i l in - ignore (Unix.write pipe s 0 (String.length s)) + ignore (Unix.write_substring pipe s 0 (String.length s)) let receive pipe = - let s = String.create 50 in - let len = Unix.read pipe s 0 (String.length s) in + let s = Bytes.create 50 in + let len = Unix.read pipe s 0 (Bytes.length s) in if len = 0 then exit 1; - Scanf.sscanf s "%d %d" (fun i l -> (i, l)) + Scanf.sscanf (Bytes.unsafe_to_string s) "%d %d" (fun i l -> (i, l)) let read mem l = let t = Utimer.start () in @@ -114,15 +114,17 @@ let spawn f = let fd = Unix.openfile "/dev/zero" [Unix.O_RDWR] 0 in let mem = try - Bigarray.Array1.map_file - fd Bigarray.char Bigarray.c_layout true mem_size + Bigarray.array1_of_genarray + (Unix.map_file + fd Bigarray.char Bigarray.c_layout true [|mem_size|]) with Sys_error _ -> (* Mac OS X does not support this, so we use a temp file instead. *) let (nm, ch) = Filename.open_temp_file "mmap" "" in Sys.remove nm; let mem = - Bigarray.Array1.map_file (Unix.descr_of_out_channel ch) - Bigarray.char Bigarray.c_layout true mem_size + Bigarray.array1_of_genarray + (Unix.map_file (Unix.descr_of_out_channel ch) + Bigarray.char Bigarray.c_layout true [|mem_size|]) in close_out ch; mem diff --git a/generic/util.ml b/generic/util.ml index 30ef289..179f043 100644 --- a/generic/util.ml +++ b/generic/util.ml @@ -43,12 +43,12 @@ let set_msg s = (****) let progress_bar f = - let s = "[ ]" in + let s = Bytes.of_string "[ ]" in let p = truncate (f *. 38.99) + 1 in - for i = 1 to p - 1 do s.[i] <- '=' done; - s.[p] <- '>'; - for i = p + 1 to 39 do s.[i] <- ' ' done; - s + for i = 1 to p - 1 do Bytes.set s i '=' done; + Bytes.set s p '>'; + for i = p + 1 to 39 do Bytes.set s i ' ' done; + Bytes.to_string s (****) @@ -155,9 +155,9 @@ let rec make_directories f = (****) -let string_extend s n c = - let s' = String.make n c in - String.blit s 0 s' 0 (String.length s); +let bytes_extend s n c = + let s' = Bytes.make n c in + Bytes.blit s 0 s' 0 (Bytes.length s); s' let array_extend a n v = @@ -168,44 +168,44 @@ let array_extend a n v = (****) module BitVect = struct - type t = string - let make n v = String.make n (if v then 'T' else 'F') - let test vect x = vect.[x] <> 'F' - let set vect x = vect.[x] <- 'T' - let clear vect x = vect.[x] <- 'F' - let copy = String.copy - let extend vect n v = string_extend vect n (if v then 'T' else 'F') - let sub = String.sub + type t = bytes + let make n v = Bytes.make n (if v then 'T' else 'F') + let test vect x = Bytes.get vect x <> 'F' + let set vect x = Bytes.set vect x 'T' + let clear vect x = Bytes.set vect x 'F' + let copy = Bytes.copy + let extend vect n v = bytes_extend vect n (if v then 'T' else 'F') + let sub = Bytes.sub let implies vect1 vect2 = - let l = String.length vect1 in - assert (String.length vect2 = l); + let l = Bytes.length vect1 in + assert (Bytes.length vect2 = l); let rec implies_rec vect1 vect2 i l = i = l || - ((vect1.[i] <> 'T' || vect2.[i] = 'T') && + ((Bytes.get vect1 i <> 'T' || Bytes.get vect2 i = 'T') && implies_rec vect1 vect2 (i + 1) l) in implies_rec vect1 vect2 0 l let lnot vect = - let l = String.length vect in - let vect' = String.make l 'F' in + let l = Bytes.length vect in + let vect' = Bytes.make l 'F' in for i = 0 to l - 1 do - vect'.[i] <- if vect.[i] = 'F' then 'T' else 'F' + Bytes.set vect' i (if Bytes.get vect i = 'F' then 'T' else 'F') done; vect' let (land) vect1 vect2 = - let l = String.length vect1 in - assert (String.length vect2 = l); - let vect = String.make l 'F' in + let l = Bytes.length vect1 in + assert (Bytes.length vect2 = l); + let vect = Bytes.make l 'F' in for i = 0 to l - 1 do - vect.[i] <- if vect1.[i] = 'F' || vect2.[i] = 'F' then 'F' else 'T' + Bytes.set vect i (if Bytes.get vect1 i = 'F' || Bytes.get vect2 i = 'F' then 'F' else 'T') done; vect let (lor) vect1 vect2 = - let l = String.length vect1 in - assert (String.length vect2 = l); - let vect = String.make l 'F' in + let l = Bytes.length vect1 in + assert (Bytes.length vect2 = l); + let vect = Bytes.make l 'F' in for i = 0 to l - 1 do - vect.[i] <- if vect1.[i] = 'F' && vect2.[i] = 'F' then 'F' else 'T' + Bytes.set vect i (if Bytes.get vect1 i = 'F' && Bytes.get vect2 i = 'F' then 'F' else 'T') done; vect end diff --git a/generic/util.mli b/generic/util.mli index 55abd1d..88ef7fe 100644 --- a/generic/util.mli +++ b/generic/util.mli @@ -60,7 +60,7 @@ end module StringTbl : Hashtbl.S with type key = string val array_extend : 'a array -> int -> 'a -> 'a array -val string_extend : string -> int -> char -> string +val bytes_extend : bytes -> int -> char -> bytes val print_list : (Format.formatter -> 'a -> unit) -> string -> diff --git a/osm/coastline.ml b/osm/coastline.ml index 6cad462..1207088 100644 --- a/osm/coastline.ml +++ b/osm/coastline.ml @@ -178,13 +178,13 @@ let load () = done; (* - let a = read_float ch in + let a = read_float ch in Format.eprintf "%f@." a; - let a = read_float ch in + let a = read_float ch in Format.eprintf "%f@." a; - let a = read_float ch in + let a = read_float ch in Format.eprintf "%f@." a; - let a = read_float ch in + let a = read_float ch in Format.eprintf "%f@." a; *) @@ -399,7 +399,7 @@ let open_rtree name ratio = let ch = open_out nm in let lengths = Array.make (leaf_size / 4) 0 in let n = ref 0 in - let buf = String.make (2 * leaf_size) '\000' in + let buf = Bytes.make (2 * leaf_size) '\000' in let pos = ref 0 in let bbox = ref Bbox.empty in let last_lat = ref 0 in @@ -534,4 +534,3 @@ let _ = build_rtree_simpl 6. "6"; build_rtree_simpl 4. "4"; build_rtree_simpl 2. "2" - diff --git a/osm/highway.ml b/osm/highway.ml index 7223beb..e098f5a 100644 --- a/osm/highway.ml +++ b/osm/highway.ml @@ -340,7 +340,7 @@ type state = type level = { mutable level_bbox : bbox; - buffer : string; + buffer : bytes; file : (int32, Bigarray.int32_elt) Mapped_file.output_stream; mutable idx : int } @@ -384,8 +384,8 @@ let _ = let latitude = Column.open_in (Column.named "highway" "sorted_node/lat") in let longitude = Column.open_in (Column.named "highway" "sorted_node/lon") in - let node_buf = String.create (16 * 1024) in - let edge_buf = String.create (16 * 1024) in + let node_buf = Bytes.create (16 * 1024) in + let edge_buf = Bytes.create (16 * 1024) in Util.make_directories (Column.file_in_database "highway/r_tree/0"); let leaves = open_out (Column.file_in_database "highway/r_tree/0") in @@ -404,7 +404,7 @@ let _ = Util.make_directories file; let st = { level_bbox = new_bbox (); - buffer = String.create (16 * 1024); + buffer = Bytes.create (16 * 1024); file = Mapped_file.open_out file node_size Mapped_file.int32; idx = 0 } in diff --git a/osm/lib/osm_display.ml b/osm/lib/osm_display.ml index 1da65fc..d873790 100644 --- a/osm/lib/osm_display.ml +++ b/osm/lib/osm_display.ml @@ -71,7 +71,7 @@ let sint_of_int i = let i' = i lsr 1 in if i land 1 = 1 then (-i' - 1) else i' let rec read_varint_rec a p v offs = let i = !p in - let c = Char.code a.[i] in + let c = Char.code (Bytes.get a i) in incr p; if c >= 0x80 then read_varint_rec a p (v lor ((c land 0x7f) lsl offs)) (offs + 7) @@ -82,7 +82,8 @@ let read_varint a p = read_varint_rec a p 0 0 let read_signed_varint a p = sint_of_int (read_varint a p) -let read_int_2 s pos = Char.code s.[pos] lor (Char.code s.[pos + 1] lsl 8) +let read_int_2 s pos = + Char.code (Bytes.get s pos) lor (Char.code (Bytes.get s (pos + 1)) lsl 8) (****) @@ -450,8 +451,8 @@ let decode_leaf ratio leaves i = node := n1; let n2 = !node + read_signed_varint buf pos in node := n2; - let cat = Char.code buf.[!pos] in - let layer = Char.code buf.[!pos + 1] in + let cat = Char.code (Bytes.get buf !pos) in + let layer = Char.code (Bytes.get buf (!pos + 1)) in pos := !pos + 2; edges.(!i) <- (n1, n2, cat, layer, nodes); incr i @@ -562,15 +563,15 @@ let surface_leaf_size = 2048 let surface_leaf_read = ref 0 let decode_surfaces ratio leaves i = - let buf = String.create surface_leaf_size in + let buf = Bytes.create surface_leaf_size in seek_in leaves (i * surface_leaf_size); really_input leaves buf 0 surface_leaf_size; let len = read_int_2 buf 0 in surface_leaf_read := !surface_leaf_read + len; let buf = if len > 1 then begin - let buf' = String.create (surface_leaf_size * len) in - String.blit buf 0 buf' 0 surface_leaf_size; + let buf' = Bytes.create (surface_leaf_size * len) in + Bytes.blit buf 0 buf' 0 surface_leaf_size; really_input leaves buf' surface_leaf_size ((len - 1) * surface_leaf_size); buf' @@ -587,8 +588,8 @@ let decode_surfaces ratio leaves i = let lst = ref [] in for i = 0 to n - 1 do let l = read_int_2 buf (4 + 4 * i) in - let cat = Char.code buf.[4 + 4 * i + 2] in - let lay = Char.code buf.[4 + 4 * i + 3] - 128 in + let cat = Char.code (Bytes.get buf (4 + 4 * i + 2)) in + let lay = Char.code (Bytes.get buf (4 + 4 * i + 3)) - 128 in if cat <> 0 then begin if !ways <> [] then lst := (!category, !layer, List.rev !ways) :: !lst; category := cat; @@ -686,7 +687,7 @@ let grow_surface pm window width height = let p = Cairo.Surface.create_similar (Cairo.get_target (Cairo_gtk.create window#misc#window)) - Cairo.COLOR_ALPHA ~width ~height + Cairo.COLOR_ALPHA ~w:width ~h:height in let r = pm.valid_rect in begin match old_p with diff --git a/osm/parser.ml b/osm/parser.ml index a96f0f2..d3a882a 100644 --- a/osm/parser.ml +++ b/osm/parser.ml @@ -43,9 +43,9 @@ let b4 ch = let uncompress sz inbuf = let zs = Zlib.inflate_init true in - let outbuf = String.create sz in + let outbuf = Bytes.create sz in let (finished, used_in, used_out) = - Zlib.inflate zs inbuf 0 (String.length inbuf) outbuf 0 sz Zlib.Z_SYNC_FLUSH + Zlib.inflate_string zs inbuf 0 (String.length inbuf) outbuf 0 sz Zlib.Z_SYNC_FLUSH in assert finished; assert (used_out = sz); @@ -81,7 +81,7 @@ let parse_blob ch = let data = uncompress raw_size zlib_data in - (typ, data) + (typ, Bytes.unsafe_to_string data) (****) @@ -429,16 +429,16 @@ let parse_primitive_block state data = (****) let perc_str f = - let s = "[ ]" in + let s = Bytes.of_string "[ ]" in let p = truncate (f *. 38.99) + 1 in - for i = 1 to p - 1 do s.[i] <- '=' done; + for i = 1 to p - 1 do Bytes.set s i '=' done; s.[p] <- '>'; - for i = p + 1 to 39 do s.[i] <- ' ' done; - s + for i = p + 1 to 39 do Bytes.set s i ' ' done; + Bytes.to_string s let parse_primitive_block = Task.funct parse_primitive_block let close_state = Task.funct (fun state () -> close_state state) -let fut = ref None +let fut = ref None let synchronize f = begin match !fut with Some f -> Task.wait f diff --git a/osm/surfaces.ml b/osm/surfaces.ml index 2e84616..9262beb 100644 --- a/osm/surfaces.ml +++ b/osm/surfaces.ml @@ -83,14 +83,14 @@ let resize_array size a = a := a' end -let resize_string size s = - let l = String.length !s in +let resize_bytes size s = + let l = Bytes.length !s in assert (l > 0); if l < size then begin let l' = ref l in while !l' < size do l' := 2 * !l' done; - let s' = String.make !l' !s.[0] in - String.blit !s 0 s' 0 l; + let s' = Bytes.make !l' (Bytes.get !s 0) in + Bytes.blit !s 0 s' 0 l; s := s' end @@ -480,7 +480,7 @@ let open_rtree name ratio = let categories = ref (Array.make (leaf_size / 8) 0) in let layers = ref (Array.make (leaf_size / 8) 0) in let n = ref 0 in - let buf = ref (String.make (256 + leaf_size) '\000') in + let buf = ref (Bytes.make (256 + leaf_size) '\000') in let pos = ref 0 in let bbox = ref Bbox.empty in let last_lat = ref 0 in @@ -501,7 +501,7 @@ Format.eprintf "%d %d %d@." len !n !pos; for i = 1 to len - 1 do Rtree.append st Bbox.empty done; - resize_string (len * leaf_size - !n * 4 - 4) buf; + resize_bytes (len * leaf_size - !n * 4 - 4) buf; output ch !buf 0 (len * leaf_size - !n * 4 - 4); n := 0; pos := 0; @@ -519,7 +519,7 @@ let ch = open_out "/tmp/c" in (fun pos (lat, lon) -> let pos = ref pos in for i = 0 to Array.length lat - 2 do - resize_string (!pos + 20) buf; + resize_bytes (!pos + 20) buf; pos := write_signed_varint !buf !pos (lat.(i) - !last_lat); (* Printf.fprintf ch "%d\n" (lat.(i) - !last_lat);