Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: fix parsing of unsigned int64 #1666

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions compiler/tests-jsoo/test_ints.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 |}]
4 changes: 2 additions & 2 deletions runtime/int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down