From 877ab354237b1bd80791dc3c534b3e33c055dfb3 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Wed, 4 Sep 2024 11:26:02 +0200 Subject: [PATCH 1/2] Runtime: fix parsing of unsigned int64 --- compiler/tests-jsoo/test_ints.ml | 14 ++++++++++++-- runtime/int64.js | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/tests-jsoo/test_ints.ml b/compiler/tests-jsoo/test_ints.ml index e0d2bd141d..dcb056a4aa 100644 --- a/compiler/tests-jsoo/test_ints.ml +++ b/compiler/tests-jsoo/test_ints.ml @@ -50,9 +50,19 @@ let%expect_test _ = let%expect_test _ = Printf.printf "%ld\n" (Int32.of_string "-0u2147483648"); [%expect {| -2147483648 |}]; - Printf.printf "%ld\n" (Int32.of_string "-0u2147483648"); + Printf.printf "%ld\n" (Int32.of_string "-0U2147483648"); [%expect {| -2147483648 |}]; Printf.printf "%ld\n" (Int32.of_string "0u2147483648"); [%expect {| -2147483648 |}]; - Printf.printf "%ld\n" (Int32.of_string "0u2147483648"); + Printf.printf "%ld\n" (Int32.of_string "0U2147483648"); [%expect {| -2147483648 |}] + +let%expect_test _ = + Printf.printf "%Ld\n" (Int64.of_string "-0u17965325103354776696"); + [%expect {| 481418970354774920 |}]; + Printf.printf "%Ld\n" (Int64.of_string "-0U17965325103354776696"); + [%expect {| 481418970354774920 |}]; + Printf.printf "%Ld\n" (Int64.of_string "0u17965325103354776696"); + [%expect {| -481418970354774920 |}]; + Printf.printf "%Ld\n" (Int64.of_string "0U17965325103354776696"); + [%expect {| -481418970354774920 |}] diff --git a/runtime/int64.js b/runtime/int64.js index d4fa66a94b..c9c6137b59 100644 --- a/runtime/int64.js +++ b/runtime/int64.js @@ -316,7 +316,7 @@ function caml_int64_format (fmt, x) { //Requires: caml_ml_string_length,caml_string_unsafe_get, MlInt64 function caml_int64_of_string(s) { var r = caml_parse_sign_and_base (s); - var i = r[0], sign = r[1], base = r[2]; + var i = r[0], sign = r[1], base = r[2], signedness = r[3]; var base64 = caml_int64_of_int32(base); var threshold = new MlInt64(0xffffff, 0xfffffff, 0xffff).udivmod(base64).quotient; @@ -338,7 +338,7 @@ function caml_int64_of_string(s) { if (caml_int64_ult(res, d)) caml_failwith("int_of_string"); } if (i != caml_ml_string_length(s)) caml_failwith("int_of_string"); - if (base == 10 && caml_int64_ult(new MlInt64(0, 0, 0x8000), res)) + if (signedness && caml_int64_ult(new MlInt64(0, 0, 0x8000), res)) caml_failwith("int_of_string"); if (sign < 0) res = caml_int64_neg(res); return res; From 5df5a25dad95727e14f398cf99115c044ad34a88 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Wed, 4 Sep 2024 21:32:21 +0200 Subject: [PATCH 2/2] CHANGES --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d72933d484..541592ce23 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,7 +15,7 @@ ## Bug fixes -* Runtime: fix parsing of unsigned integers (0u2147483648) +* Runtime: fix parsing of unsigned integers (0u2147483648) (#1633, #1666) * Toplevel: fix missing primitives with separate compilation * Compiler: fix link of packed modules with separate compilation * Fixed the static evaluation of some equalities (#1659)