The unpac monorepo manager self-hosting as a monorepo using unpac

Safe-string support (closes #8).

+52 -43
+1 -1
vendor/opam/jsonm/.merlin
··· 1 - PKG uchar uutf 1 + PKG bytes uchar uutf 2 2 S src 3 3 S test 4 4 B _build/src
+1
vendor/opam/jsonm/CHANGES.md
··· 1 1 2 + - Safe-string suport. 2 3 - Uchar.t support. At the API level only `Jsonm.error` changes. 3 4 - Build depend on topkg. 4 5 - Relicensed from BSD3 to ISC.
+1 -1
vendor/opam/jsonm/_tags
··· 1 - true : bin_annot, package(uchar), package(uutf) 1 + true : bin_annot, safe_string, package(bytes), package(uchar), package(uutf) 2 2 <src> : include 3 3 <test> : include 4 4 <test/jsontrip.*> : package(unix)
+14 -8
vendor/opam/jsonm/src/jsonm.ml
··· 9 9 let io_buffer_size = 65536 (* IO_BUFFER_SIZE 4.0.0 *) 10 10 let pp = Format.fprintf 11 11 12 - (* Unsafe string byte manipulations. If you don't believe the authors's 12 + (* Unsafe string and bytes manipulations. If you don't believe the authors's 13 13 invariants, replacing with safe versions makes everything safe in the 14 14 module. He won't be upset. *) 15 15 16 - let unsafe_blit = String.unsafe_blit 17 - let unsafe_set_byte s j byte = String.unsafe_set s j (Char.unsafe_chr byte) 18 16 let unsafe_byte s j = Char.code (String.unsafe_get s j) 17 + 18 + let unsafe_blit s soff d doff = 19 + Bytes.unsafe_blit (Bytes.unsafe_of_string s) soff d doff 20 + 21 + let unsafe_set_byte s j byte = Bytes.unsafe_set s j (Char.unsafe_chr byte) 19 22 20 23 (* Characters and their classes *) 21 24 ··· 426 429 type encoder = 427 430 { dst : dst; (* output destination. *) 428 431 minify : bool; (* [true] for compact output. *) 429 - mutable o : string; (* current output chunk. *) 432 + mutable o : Bytes.t; (* current output chunk. *) 430 433 mutable o_pos : int; (* next output position to write. *) 431 434 mutable o_max : int; (* maximal output position to write. *) 432 435 buf : Buffer.t; (* buffer to format floats. *) ··· 439 442 440 443 let o_rem e = e.o_max - e.o_pos + 1 (* remaining bytes to write in [e.o]. *) 441 444 let dst e s j l = (* set [e.o] with [s]. *) 442 - if (j < 0 || l < 0 || j + l > String.length s) then invalid_bounds j l; 445 + if (j < 0 || l < 0 || j + l > Bytes.length s) then invalid_bounds j l; 443 446 e.o <- s; e.o_pos <- j; e.o_max <- j + l - 1 444 447 445 448 let partial k e = function `Await -> k e | v -> expect_await v 446 449 let flush k e = match e.dst with (* get free space in [d.o] and [k]ontinue. *) 447 450 | `Manual -> e.k <- partial k; `Partial 448 - | `Buffer b -> Buffer.add_substring b e.o 0 e.o_pos; e.o_pos <- 0; k e 449 451 | `Channel oc -> output oc e.o 0 e.o_pos; e.o_pos <- 0; k e 452 + | `Buffer b -> 453 + let o = Bytes.unsafe_to_string e.o in 454 + Buffer.add_substring b o 0 e.o_pos; e.o_pos <- 0; k e 455 + 450 456 451 457 let rec writeb b k e = (* write byte [b] and [k]ontinue. *) 452 458 if e.o_pos > e.o_max then flush (writeb b k) e else ··· 594 600 595 601 let encoder ?(minify = true) dst = 596 602 let o, o_pos, o_max = match dst with 597 - | `Manual -> "", 1, 0 (* implies [o_rem e = 0]. *) 603 + | `Manual -> Bytes.empty, 1, 0 (* implies [o_rem e = 0]. *) 598 604 | `Buffer _ 599 - | `Channel _ -> String.create io_buffer_size, 0, io_buffer_size - 1 605 + | `Channel _ -> Bytes.create io_buffer_size, 0, io_buffer_size - 1 600 606 in 601 607 { dst = (dst :> dst); minify; o; o_pos; o_max; buf = Buffer.create 30; 602 608 stack = []; nest = 0; next_name = false; last_start = false;
+7 -7
vendor/opam/jsonm/src/jsonm.mli
··· 193 193 {b Warning.} Use only with [`Manual] decoders and encoders. *) 194 194 module Manual : sig 195 195 196 - val src : decoder -> string -> int -> int -> unit 196 + val src : decoder -> Bytes.t -> int -> int -> unit 197 197 (** [src d s j l] provides [d] with [l] bytes to read, starting 198 198 at [j] in [s]. This byte range is read by calls to {!decode} until 199 199 [`Await] is returned. To signal the end of input call the function 200 200 with [l = 0]. *) 201 201 202 - val dst : encoder -> string -> int -> int -> unit 202 + val dst : encoder -> Bytes.t -> int -> int -> unit 203 203 (** [dst e s j l] provides [e] with [l] bytes to write, starting 204 204 at [j] in [s]. This byte range is written by calls to {!encode} with [e] 205 205 until [`Partial] is returned. Use {!dst_rem} to know the remaining ··· 389 389 let wc = write fd s j l in 390 390 if wc < l then unix_write fd s (j + wc) (l - wc) else () 391 391 in 392 - unix_write fd s 0 (String.length s - Jsonm.Manual.dst_rem e); 392 + unix_write fd s 0 (Bytes.length s - Jsonm.Manual.dst_rem e); 393 393 Jsonm.Manual.dst e s 0 (String.length s); 394 394 encode fd s e `Await 395 395 in ··· 401 401 let rec unix_read fd s j l = try Unix.read fd s j l with 402 402 | Unix.Unix_error (Unix.EINTR, _, _) -> unix_read fd s j l 403 403 in 404 - let rc = unix_read fdi ds 0 (String.length ds) in 404 + let rc = unix_read fdi ds 0 (Bytes.length ds) in 405 405 Jsonm.Manual.src d ds 0 rc; loop fdi fdo ds es d e 406 406 in 407 - let ds = String.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 408 - let es = String.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 407 + let ds = Bytes.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 408 + let es = Bytes.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 409 409 let d = Jsonm.decoder ?encoding `Manual in 410 410 let e = Jsonm.encoder ?minify `Manual in 411 - Jsonm.Manual.dst e es 0 (String.length es); 411 + Jsonm.Manual.dst e es 0 (Bytes.length es); 412 412 loop fdi fdo ds es d e 413 413 ]} 414 414 {2:memsel Member selection}
+6 -6
vendor/opam/jsonm/test/examples.ml
··· 30 30 let wc = write fd s j l in 31 31 if wc < l then unix_write fd s (j + wc) (l - wc) else () 32 32 in 33 - unix_write fd s 0 (String.length s - Jsonm.Manual.dst_rem e); 34 - Jsonm.Manual.dst e s 0 (String.length s); 33 + unix_write fd s 0 (Bytes.length s - Jsonm.Manual.dst_rem e); 34 + Jsonm.Manual.dst e s 0 (Bytes.length s); 35 35 encode fd s e `Await 36 36 in 37 37 let rec loop fdi fdo ds es d e = match Jsonm.decode d with ··· 42 42 let rec unix_read fd s j l = try Unix.read fd s j l with 43 43 | Unix.Unix_error (Unix.EINTR, _, _) -> unix_read fd s j l 44 44 in 45 - let rc = unix_read fdi ds 0 (String.length ds) in 45 + let rc = unix_read fdi ds 0 (Bytes.length ds) in 46 46 Jsonm.Manual.src d ds 0 rc; loop fdi fdo ds es d e 47 47 in 48 - let ds = String.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 49 - let es = String.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 48 + let ds = Bytes.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 49 + let es = Bytes.create 65536 (* UNIX_BUFFER_SIZE in 4.0.0 *) in 50 50 let d = Jsonm.decoder ?encoding `Manual in 51 51 let e = Jsonm.encoder ?minify `Manual in 52 - Jsonm.Manual.dst e es 0 (String.length es); 52 + Jsonm.Manual.dst e es 0 (Bytes.length es); 53 53 loop fdi fdo ds es d e 54 54 55 55 (* Member selection *)
+22 -20
vendor/opam/jsonm/test/jsontrip.ml
··· 33 33 let b = Buffer.create unix_buffer_size in 34 34 let input, s = 35 35 if use_unix 36 - then unix_read (Unix.descr_of_in_channel ic), String.create unix_buffer_size 37 - else input ic, String.create io_buffer_size 36 + then unix_read (Unix.descr_of_in_channel ic), Bytes.create unix_buffer_size 37 + else input ic, Bytes.create io_buffer_size 38 38 in 39 39 let rec loop b input s = 40 - let rc = input s 0 (String.length s) in 40 + let rc = input s 0 (Bytes.length s) in 41 41 if rc = 0 then Buffer.contents b else 42 - (Buffer.add_substring b s 0 rc; loop b input s) 42 + let us = Bytes.unsafe_to_string s in 43 + (Buffer.add_substring b us 0 rc; loop b input s) 43 44 in 44 45 loop b input s 45 46 46 - let string_to_channel use_unix oc s = 47 - if use_unix 48 - then unix_write (Unix.descr_of_out_channel oc) s 0 (String.length s) 49 - else output_string oc s 47 + let string_to_channel use_unix oc s = match use_unix with 48 + | false -> output_string oc s 49 + | true -> 50 + let s = Bytes.unsafe_of_string s in 51 + unix_write (Unix.descr_of_out_channel oc) s 0 (Bytes.length s) 50 52 51 53 let dst_for sout = if sout then `Buffer (Buffer.create 512) else `Channel stdout 52 54 let src_for inf sin use_unix = ··· 68 70 69 71 let rec encode_unix encode fd s e v = match encode e v with `Ok -> () 70 72 | `Partial -> 71 - unix_write fd s 0 (String.length s - Jsonm.Manual.dst_rem e); 72 - Jsonm.Manual.dst e s 0 (String.length s); 73 + unix_write fd s 0 (Bytes.length s - Jsonm.Manual.dst_rem e); 74 + Jsonm.Manual.dst e s 0 (Bytes.length s); 73 75 encode_unix encode fd s e `Await 74 76 75 77 (* Dump *) ··· 86 88 let decode = if uncut then Jsonm.Uncut.decode else Jsonm.decode in 87 89 let rec loop decode fd s d = match decode d with 88 90 | `Await -> 89 - let rc = unix_read fd s 0 (String.length s) in 91 + let rc = unix_read fd s 0 (Bytes.length s) in 90 92 Jsonm.Manual.src d s 0 rc; loop decode fd s d 91 93 | v -> 92 94 pr_decode Format.std_formatter inf d v; 93 95 if v <> `End then loop decode fd s d 94 96 in 95 - loop decode fd (String.create usize) (Jsonm.decoder ?encoding `Manual); 97 + loop decode fd (Bytes.create usize) (Jsonm.decoder ?encoding `Manual); 96 98 close_src_unix fd 97 99 98 100 let dump inf sin use_unix usize ie uncut = ··· 127 129 | `Comment _ | `White _ -> loop decode fd s d 128 130 | `Error e -> log_error inf d e; loop decode fd s d 129 131 | `Await -> 130 - let rc = unix_read fd s 0 (String.length s) in 132 + let rc = unix_read fd s 0 (Bytes.length s) in 131 133 Jsonm.Manual.src d s 0 rc; loop decode fd s d 132 134 in 133 - loop decode fd (String.create usize) (Jsonm.decoder ?encoding `Manual) 135 + loop decode fd (Bytes.create usize) (Jsonm.decoder ?encoding `Manual) 134 136 135 137 let decode inf sin use_unix usize ie uncut = 136 138 if sin || not use_unix then decode_ inf ie uncut (src_for inf use_unix sin) ··· 235 237 fun v -> r_uncut enc buf; enc v; r_uncut enc buf 236 238 237 239 let encode_f_unix usize buf uncut minify fd = 238 - let e, s = Jsonm.encoder ~minify `Manual, String.create usize in 239 - Jsonm.Manual.dst e s 0 (String.length s); 240 + let e, s = Jsonm.encoder ~minify `Manual, Bytes.create usize in 241 + Jsonm.Manual.dst e s 0 (Bytes.length s); 240 242 if not uncut then (fun v -> encode_unix Jsonm.encode fd s e v) else 241 243 let enc v = encode_unix Jsonm.Uncut.encode fd s e v in 242 244 fun v -> r_uncut enc buf; enc v; r_uncut enc buf ··· 280 282 loop decode fdi fdo ds es d e 281 283 | `Error err -> log_error inf d err 282 284 | `Await -> 283 - let rc = unix_read fdi ds 0 (String.length ds) in 285 + let rc = unix_read fdi ds 0 (Bytes.length ds) in 284 286 Jsonm.Manual.src d ds 0 rc; loop decode fdi fdo ds es d e 285 287 in 286 - let d, ds = Jsonm.decoder ?encoding `Manual, String.create usize in 287 - let e, es = Jsonm.encoder ~minify `Manual, String.create usize in 288 - Jsonm.Manual.dst e es 0 (String.length es); 288 + let d, ds = Jsonm.decoder ?encoding `Manual, Bytes.create usize in 289 + let e, es = Jsonm.encoder ~minify `Manual, Bytes.create usize in 290 + Jsonm.Manual.dst e es 0 (Bytes.length es); 289 291 loop decode fdi fdo ds es d e; close_src_unix fdi 290 292 291 293 let trip inf sin sout use_unix usize ie uncut minify =