Skip to content

Commit

Permalink
Runtime: fix for OCaml.5.1.1 (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo authored Nov 27, 2023
1 parent 21ea765 commit a3be888
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Lib: add download attribute to anchor element
* Misc: switch CI to OCaml 5.1
* Misc: preliminary support for OCaml 5.2
* Misc: support for OCaml 5.1.1

## Bug fixes
* Runtime: fix Dom_html.onIE (#1493)
Expand Down
11 changes: 5 additions & 6 deletions compiler/tests-jsoo/test_marshal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ let%expect_test _ =
| _ -> assert false
in
let s =
match Sys.backend_type with
| Other "js_of_ocaml" -> Marshal.from_string data 0
| Other _ | Native | Bytecode ->
if ocaml_5_1 && not (Sys.win32 || Sys.cygwin)
then Marshal.from_string data 0
else String.make 10000 'c'
(* This would only work on OCaml 5.1.0 if we were not linking
against compiler-libs *)
if ocaml_5_1 && not (Sys.win32 || Sys.cygwin)
then Marshal.from_string data 0
else String.make 10000 'c'
in
Printf.printf "%s ... (%d)\n" (String.sub s 0 20) (String.length s);
[%expect {| cccccccccccccccccccc ... (10000) |}]
Expand Down
14 changes: 9 additions & 5 deletions runtime/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ var caml_custom_ops =
//Provides: caml_input_value_from_reader mutable
//Requires: caml_failwith
//Requires: caml_float_of_bytes, caml_custom_ops
//Requires: zstd_decompress
//Requires: UInt8ArrayReader
//Requires: caml_decompress_input
function caml_input_value_from_reader(reader, ofs) {
function readvlq(overflow) {
var c = reader.read8u();
Expand Down Expand Up @@ -483,10 +483,14 @@ function caml_input_value_from_reader(reader, ofs) {
}
}
if(compressed) {
var data = reader.readuint8array(data_len);
var res = new Uint8Array(uncompressed_data_len);
var res = zstd_decompress(data, res);
var reader = new UInt8ArrayReader(res, 0);
if(caml_decompress_input) {
var data = reader.readuint8array(data_len);
var res = new Uint8Array(uncompressed_data_len);
var res = caml_decompress_input(data, res);
var reader = new UInt8ArrayReader(res, 0);
} else {
caml_failwith("input_value: compressed object, cannot decompress");
}
}
var res = intern_rec (reader);
while (stack.length > 0) {
Expand Down
33 changes: 33 additions & 0 deletions runtime/zstd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

//Provides: zstd_decompress
//Version: >= 5.1
var zstd_decompress = (function () {
"use strict";
// aliases for shorter compressed code (most minifers don't do this)
Expand Down Expand Up @@ -644,3 +645,35 @@ return function decompress(dat, buf) {
return cct(bufs, ol);
}
}) ()


//Provides: caml_decompress_input
//Version: > 5.1.0
var caml_decompress_input = null

//Provides: caml_decompress_input
//Version: < 5.1.0
var caml_decompress_input = null

//Provides: caml_zstd_initialize
//Requires: caml_decompress_input
//Requires: zstd_decompress
//Version: >= 5.1.1
function caml_zstd_initialize(unit) {
caml_decompress_input = zstd_decompress;
return 1
}

//Provides: caml_decompress_input
//Version: >= 5.1
//Version: < 5.1.1
//Requires: zstd_decompress
var caml_decompress_input = zstd_decompress;


//Provides: caml_compression_available
//Requires: caml_decompress_input
//Version: >= 5.1.1
function caml_compression_available() {
return caml_decompress_input ? 1 : 0;
}

0 comments on commit a3be888

Please sign in to comment.