From 1db6d0e0bc8d2f70dc4465c5fb6c1200140ad928 Mon Sep 17 00:00:00 2001 From: "J.-F. Cap" Date: Thu, 14 Mar 2019 20:54:38 +0100 Subject: [PATCH] Trap INT64_MIN / -1 exception --- src/core/bigint.c | 35 ++++++++++++++++++++++++--- test/suite6.janet | 60 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/src/core/bigint.c b/src/core/bigint.c index 99165139..a256e97b 100644 --- a/src/core/bigint.c +++ b/src/core/bigint.c @@ -85,7 +85,8 @@ static const JanetAbstractType bi_uint64_type = { static int parse_int64(const char *str, bi_int64 *box) { char *endptr; - int base = (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) ? 16 : 10; + int base = ((str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) || + (str[0] == '-' && str[1] == '0' && (str[2] == 'x' || str[2] == 'X'))) ? 16 : 10; errno = 0; *box = (bi_int64)strtoll(str, &endptr, base); if ((errno == ERANGE && (*box == LLONG_MAX || *box == LLONG_MIN)) || @@ -239,6 +240,33 @@ static Janet cfun_##type##_##name##_mut(int32_t argc, Janet *argv) { \ return janet_wrap_abstract(box); \ } +#define DIVMETHOD_SIGNED(type,name,oper) \ +static Janet cfun_##type##_##name(int32_t argc, Janet *argv) { \ + janet_arity(argc, 2, -1); \ + bi_##type *box = (bi_##type *)janet_abstract(&bi_##type##_type, sizeof(bi_##type)); \ + *box = check_bi_##type(argv[0]); \ + for (int i=1;i