Skip to content

Commit

Permalink
Runtime: fix incorrect pos_in after unmarshall
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Sep 11, 2024
1 parent 33d2736 commit b2f3bae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

## Bug fixes
* Runtime: fix parsing of unsigned integers (0u2147483648) (#1633, #1666)
* Runtime: fix incorrect pos_in after unmarshalling
* Toplevel: fix missing primitives with separate compilation
* Compiler: fix link of packed modules with separate compilation
* Compiler: Fixed the static evaluation of some equalities (#1659)
Expand Down
43 changes: 38 additions & 5 deletions compiler/tests-jsoo/test_channel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,58 @@ let%expect_test _ =

let marshal_out_segment f ch v =
let start = pos_out ch in
Format.printf "start=%d\n%!" start;
let start' = LargeFile.pos_out ch in
seek_out ch 0;
seek_out ch start;
Format.printf "start=%d %Ld\n%!" start start';
output_binary_int ch 0;
(* dummy value for stop *)
marshal_out ch v;
let stop = pos_out ch in
let stop' = LargeFile.pos_out ch in
Format.printf "stop=%d %Ld\n%!" stop stop';
seek_out ch start;
output_binary_int ch stop;
seek_out ch stop;
Digest.output ch (Digest.file f)

let read_segment _f ch =
let start = pos_in ch in
let start' = LargeFile.pos_in ch in
seek_in ch 0;
seek_in ch start;
Format.printf "start=%d %Ld\n%!" start start';
let stop = input_binary_int ch in
let _ = input_value ch in
let stop2 = pos_in ch in
let stop2' = LargeFile.pos_in ch in
Format.printf "stop=%d %d %Ld\n%!" stop stop2 stop2';
let _ = Digest.input ch in
()

let _ =
let tmp = Filename.temp_file "out" "txt" in
let filename = tmp in
let chan = open_out_bin filename in
output_binary_int chan 8900;
marshal_out_segment filename chan [ "output"; "data" ];
marshal_out_segment filename chan [ "more"; "stuff" ]
marshal_out_segment filename chan [ "more"; "stuff" ];
close_out chan;
let chan = open_in_bin filename in
let _ = input_binary_int chan in
read_segment filename chan;
read_segment filename chan;
close_in chan
end in
let open! M in
[%expect {|
start=4
start=59 |}]
[%expect
{|
start=4 4
stop=43 43
start=59 59
stop=97 97
start=4 4
stop=43 43 43
start=59 59
stop=97 97 97
|}]
4 changes: 1 addition & 3 deletions runtime/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ function caml_input_value (chanid) {
var r = block(buf, caml_marshal_header_size, len)
if(r < len)
caml_failwith("input_value: truncated object " + r + " " + len);
var offset = [0];
var res = caml_input_value_from_bytes(caml_bytes_of_array(buf), offset);
chan.offset = chan.offset + offset[0];
var res = caml_input_value_from_bytes(caml_bytes_of_array(buf), 0);
return res;
}

Expand Down
1 change: 0 additions & 1 deletion runtime/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ function caml_input_value_from_reader(reader, ofs) {
if (d < size) stack.push(v, size);
v[d] = intern_rec (reader);
}
if (typeof ofs!="number") ofs[0] = reader.i;
return res;
}

Expand Down

0 comments on commit b2f3bae

Please sign in to comment.