Skip to content

Commit 360fdd0

Browse files
committed
fix #4599
1 parent 245f30a commit 360fdd0

22 files changed

+94
-54
lines changed

jscomp/core/lam_compile_primitive.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,13 @@ let translate loc
492492
Bytes is an int array in javascript
493493
*)
494494
| Pbytessetu
495-
| Pbytessets ->
495+
->
496496
(match args with
497497
| [e;e0;e1] -> ensure_value_unit cxt.continuation
498498
(Js_of_lam_string.set_byte e e0 e1)
499499
| _ -> assert false)
500+
| Pbytessets ->
501+
E.runtime_call Js_runtime_modules.bytes "set" args
500502
| Pbytesrefu ->
501503
(match args with
502504
| [e;e1] -> Js_of_lam_string.ref_byte e e1

jscomp/runtime/caml_bytes.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ external (.![]<-) : bytes -> int -> char -> unit = "%bytes_unsafe_set"
3030
external length : bytes -> int = "%bytes_length"
3131

3232

33+
let set s i ch =
34+
if i < 0 || i >= length s then
35+
raise (Invalid_argument "index out of bounds")
36+
else s.![i] <- ch
3337

3438
let get s i =
3539
if i < 0 || i >= length s then

jscomp/runtime/caml_bytes.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
val caml_create_bytes : int -> bytes
2727
val caml_fill_bytes : bytes -> int -> int -> char -> unit
2828
val get : bytes -> int -> char
29+
val set :
30+
bytes ->
31+
int ->
32+
char ->
33+
unit
2934
val bytes_to_string : bytes -> string
3035
val caml_blit_bytes : bytes -> int -> bytes -> int -> int -> unit
3136

jscomp/runtime/release.ninja

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ build runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.ml |
2929
build runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3030
build runtime/caml_int32.cmj : cc_cmi runtime/caml_int32.ml | runtime/caml_int32.cmi runtime/caml_nativeint_extern.cmj
3131
build runtime/caml_int32.cmi : cc runtime/caml_int32.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
32-
build runtime/caml_int64.cmj : cc_cmi runtime/caml_int64.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_int64.cmi runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj runtime/js.cmj
32+
build runtime/caml_int64.cmj : cc_cmi runtime/caml_int64.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_int64.cmi runtime/caml_nativeint_extern.cmj runtime/caml_primitive.cmj runtime/caml_string_extern.cmj runtime/js.cmj
3333
build runtime/caml_int64.cmi : cc runtime/caml_int64.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3434
build runtime/caml_io.cmj : cc_cmi runtime/caml_io.ml | runtime/caml_io.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmj runtime/js.cmj
3535
build runtime/caml_io.cmi : cc runtime/caml_io.mli | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -39,9 +39,9 @@ build runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.ml | runtime/caml_array_ext
3939
build runtime/caml_md5.cmi : cc runtime/caml_md5.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4040
build runtime/caml_module.cmj : cc_cmi runtime/caml_module.ml | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
4141
build runtime/caml_module.cmi : cc runtime/caml_module.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
42-
build runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.ml | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
42+
build runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.ml | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/caml_primitive.cmj runtime/js.cmj
4343
build runtime/caml_obj.cmi : cc runtime/caml_obj.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
44-
build runtime/caml_oo.cmj : cc_cmi runtime/caml_oo.ml | runtime/caml_array_extern.cmj runtime/caml_exceptions.cmj runtime/caml_oo.cmi
44+
build runtime/caml_oo.cmj : cc_cmi runtime/caml_oo.ml | runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/caml_exceptions.cmj runtime/caml_oo.cmi
4545
build runtime/caml_oo.cmi : cc runtime/caml_oo.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4646
build runtime/caml_option.cmj : cc_cmi runtime/caml_option.ml | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj
4747
build runtime/caml_option.cmi : cc runtime/caml_option.mli | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -61,10 +61,10 @@ build runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc
6161
build runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6262
build runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj : cc runtime/caml_int32_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6363
build runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
64-
build runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.ml | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj
64+
build runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.ml | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
6565
build runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6666
build runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj : cc runtime/caml_oo_curry.ml | runtime/bs_stdlib_mini.cmi runtime/caml_oo.cmj runtime/curry.cmj runtime/js.cmi runtime/js.cmj
6767
build runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6868
build runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
69-
build runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.ml | runtime/bs_stdlib_mini.cmi runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj
69+
build runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.ml | runtime/bs_stdlib_mini.cmi runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj
7070
build runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_gc.cmi runtime/caml_gc.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_io.cmi runtime/caml_io.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_oo.cmi runtime/caml_oo.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_primitive.cmi runtime/caml_primitive.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int32_extern.cmi runtime/caml_int32_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_oo_curry.cmi runtime/caml_oo_curry.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj

jscomp/test/bytes_split_gpr_743_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ var b = [
3838
0
3939
];
4040

41-
b[0] = /* "a" */97;
41+
Caml_bytes.set(b, 0, /* "a" */97);
4242

43-
b[1] = /* "b" */98;
43+
Caml_bytes.set(b, 1, /* "b" */98);
4444

45-
b[2] = /* "c" */99;
45+
Caml_bytes.set(b, 2, /* "c" */99);
4646

4747
Bytes.blit(b, 0, b, 1, 2);
4848

@@ -61,11 +61,11 @@ var b$1 = [
6161
0
6262
];
6363

64-
b$1[0] = /* "a" */97;
64+
Caml_bytes.set(b$1, 0, /* "a" */97);
6565

66-
b$1[1] = /* "b" */98;
66+
Caml_bytes.set(b$1, 1, /* "b" */98);
6767

68-
b$1[2] = /* "c" */99;
68+
Caml_bytes.set(b$1, 2, /* "c" */99);
6969

7070
Bytes.blit(b$1, 1, b$1, 0, 2);
7171

jscomp/test/gray_code_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var Bytes = require("../../lib/js/bytes.js");
4+
var Caml_bytes = require("../../lib/js/caml_bytes.js");
45

56
function gray_encode(b) {
67
return b ^ (b >>> 1);
@@ -29,7 +30,7 @@ function bool_string(len, n) {
2930
var n$1 = _n;
3031
var i = _i;
3132
if ((n$1 & 1) === 1) {
32-
s[i] = /* "1" */49;
33+
Caml_bytes.set(s, i, /* "1" */49);
3334
}
3435
if (i <= 0) {
3536
return s;

jscomp/test/ocaml_parsetree_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12018,7 +12018,7 @@ function remove_underscores(s) {
1201812018
}
1201912019
var c = Caml_string.get(s, src);
1202012020
if (c !== 95) {
12021-
b[dst] = c;
12021+
Caml_bytes.set(b, dst, c);
1202212022
_dst = dst + 1 | 0;
1202312023
_src = src + 1 | 0;
1202412024
continue ;

jscomp/test/ocaml_re_test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,8 @@ function is_charset(_param) {
17811781
function split(s, cm) {
17821782
var _t = s;
17831783
var f = function (i, j) {
1784-
cm[i] = /* "\001" */1;
1785-
cm[j + 1 | 0] = /* "\001" */1;
1786-
1784+
Caml_bytes.set(cm, i, /* "\001" */1);
1785+
return Caml_bytes.set(cm, j + 1 | 0, /* "\001" */1);
17871786
};
17881787
while(true) {
17891788
var t = _t;
@@ -1902,14 +1901,14 @@ function flatten_cmap(cm) {
19021901
var c = Caml_bytes.caml_create_bytes(256);
19031902
var col_repr = Caml_bytes.caml_create_bytes(256);
19041903
var v = 0;
1905-
c[0] = /* "\000" */0;
1906-
col_repr[0] = /* "\000" */0;
1904+
Caml_bytes.set(c, 0, /* "\000" */0);
1905+
Caml_bytes.set(col_repr, 0, /* "\000" */0);
19071906
for(var i = 1; i <= 255; ++i){
19081907
if (Caml_bytes.get(cm, i) !== /* "\000" */0) {
19091908
v = v + 1 | 0;
19101909
}
1911-
c[i] = Char.chr(v);
1912-
col_repr[v] = Char.chr(i);
1910+
Caml_bytes.set(c, i, Char.chr(v));
1911+
Caml_bytes.set(col_repr, v, Char.chr(i));
19131912
}
19141913
return [
19151914
c,

jscomp/test/ocaml_typedtree_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23255,7 +23255,7 @@ function remove_underscores(s) {
2325523255
}
2325623256
var c = Caml_string.get(s, src);
2325723257
if (c !== 95) {
23258-
b[dst] = c;
23258+
Caml_bytes.set(b, dst, c);
2325923259
_dst = dst + 1 | 0;
2326023260
_src = src + 1 | 0;
2326123261
continue ;

jscomp/test/parser_api.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,7 @@ function get(tbl, ind) {
13301330
}
13311331

13321332
function set(tbl, ind, c) {
1333-
Caml_array.caml_array_get(tbl, Caml_int32.div(ind, Sys.max_string_length))[Caml_int32.mod_(ind, Sys.max_string_length)] = c;
1334-
1333+
return Caml_bytes.set(Caml_array.caml_array_get(tbl, Caml_int32.div(ind, Sys.max_string_length)), Caml_int32.mod_(ind, Sys.max_string_length), c);
13351334
}
13361335

13371336
function blit(src, srcoff, dst, dstoff, len) {
@@ -15261,7 +15260,7 @@ function remove_underscores(s) {
1526115260
}
1526215261
var c = Caml_string.get(s, src);
1526315262
if (c !== 95) {
15264-
b[dst] = c;
15263+
Caml_bytes.set(b, dst, c);
1526515264
_dst = dst + 1 | 0;
1526615265
_src = src + 1 | 0;
1526715266
continue ;

0 commit comments

Comments
 (0)