Skip to content

Commit

Permalink
Merge pull request #995 from sim642/ocaml-5.1-marshal
Browse files Browse the repository at this point in the history
Fix `Lwt_io.read_value` on OCaml 5.1
  • Loading branch information
raphael-proust authored Jul 17, 2023
2 parents e0ebd72 + 318b0f8 commit fc8edd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

* Fix race in worker loop. (Thomas Leonard, #993, #994)

* Fix marshall header size in Lwt_io.read_value. (Simmo Saan, #995)


===== 5.6.1 =====

Expand Down
10 changes: 5 additions & 5 deletions src/unix/lwt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,12 @@ struct
Lwt.return (Bytes.unsafe_to_string buf)

let read_value ic =
let header = Bytes.create 20 in
unsafe_read_into_exactly ic header 0 20 >>= fun () ->
let header = Bytes.create Marshal.header_size in
unsafe_read_into_exactly ic header 0 Marshal.header_size >>= fun () ->
let bsize = Marshal.data_size header 0 in
let buffer = Bytes.create (20 + bsize) in
Bytes.unsafe_blit header 0 buffer 0 20;
unsafe_read_into_exactly ic buffer 20 bsize >>= fun () ->
let buffer = Bytes.create (Marshal.header_size + bsize) in
Bytes.unsafe_blit header 0 buffer 0 Marshal.header_size;
unsafe_read_into_exactly ic buffer Marshal.header_size bsize >>= fun () ->
Lwt.return (Marshal.from_bytes buffer 0)

(* +---------------------------------------------------------------+
Expand Down

0 comments on commit fc8edd6

Please sign in to comment.