readint.c (mrb_int_read): new function.

We no longer use `mrb_read_int` which is kinda compatible with `strtol`.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-11-05 23:36:49 +09:00
parent 440adc447b
commit 4e9773ae3d
6 changed files with 23 additions and 21 deletions
+5 -3
View File
@@ -254,12 +254,14 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len)
num = (int)mrb_as_int(mrb, tmp_v); \
} while (0)
static const char *
static const char*
get_num(mrb_state *mrb, const char *p, const char *end, int *valp)
{
char *e;
mrb_int n = mrb_int_read(p, end, &e);
if (e == NULL || n > INT_MAX) return NULL;
mrb_int n;
if (!mrb_read_int(p, end, &e, &n)) {
return NULL;
}
*valp = (int)n;
return e;
}