Use `mrb_int_value()` instead of `mrb_fixnum_value()`.
Where fixnum overflow can happen.
MODIFY
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
@@ -2465,7 +2465,7 @@ codegen(codegen_scope *s, node *tree, int val)
int off;
lit_int:
- off = new_lit(s, mrb_fixnum_value(i));
+ off = new_lit(s, mrb_int_value(s->mrb, i));
genop_2(s, OP_LOADL, cursp(), off);
}
}
@@ -2528,7 +2528,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
}
else {
- int off = new_lit(s, mrb_fixnum_value(i));
+ int off = new_lit(s, mrb_int_value(s->mrb, i));
genop_2(s, OP_LOADL, cursp(), off);
}
#ifndef MRB_NO_FLOAT

MODIFY
mrbgems/mruby-io/src/file.c
mrbgems/mruby-io/src/file.c
@@ -399,7 +399,7 @@ mrb_file_mtime(mrb_state *mrb, mrb_value self)
if (mrb_fstat(fd, &st) == -1)
return mrb_false_value();
- return mrb_fixnum_value((mrb_int)st.st_mtime);
+ return mrb_int_value(mrb, (mrb_int)st.st_mtime);
}
static mrb_value

MODIFY
mrbgems/mruby-io/src/file_test.c
mrbgems/mruby-io/src/file_test.c
@@ -304,7 +304,7 @@ mrb_filetest_s_size(mrb_state *mrb, mrb_value klass)
if (mrb_stat(mrb, obj, &st) < 0)
mrb_sys_fail(mrb, "mrb_stat");
- return mrb_fixnum_value(st.st_size);
+ return mrb_int_value(mrb, st.st_size);
}
/*
@@ -326,7 +326,7 @@ mrb_filetest_s_size_p(mrb_state *mrb, mrb_value klass)
if (st.st_size == 0)
return mrb_nil_value();
- return mrb_fixnum_value(st.st_size);
+ return mrb_int_value(mrb, st.st_size);
}
void

MODIFY
mrbgems/mruby-random/src/random.c
mrbgems/mruby-random/src/random.c
@@ -131,7 +131,7 @@ random_rand(mrb_state *mrb, rand_state *t, mrb_value max)
#endif
}
else {
- value = mrb_fixnum_value(rand_uint32(t) % mrb_integer(max));
+ value = mrb_int_value(mrb, rand_uint32(t) % mrb_integer(max));
}
return value;
@@ -224,7 +224,7 @@ random_m_srand(mrb_state *mrb, mrb_value self)
}
old_seed = rand_seed(t, seed);
- return mrb_fixnum_value((mrb_int)old_seed);
+ return mrb_int_value(mrb, (mrb_int)old_seed);
}
/*
@@ -378,7 +378,7 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary)
}
break;
}
- mrb_ary_push(mrb, result, mrb_fixnum_value(r));
+ mrb_ary_push(mrb, result, mrb_int_value(mrb, r));
}
for (i=0; i<n; i++) {
mrb_int idx = mrb_integer(RARRAY_PTR(result)[i]);

MODIFY
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
@@ -60,14 +60,14 @@ static mrb_value
rational_numerator(mrb_state *mrb, mrb_value self)
{
struct mrb_rational *p = rational_ptr(mrb, self);
- return mrb_fixnum_value(p->numerator);
+ return mrb_int_value(mrb, p->numerator);
}
static mrb_value
rational_denominator(mrb_state *mrb, mrb_value self)
{
struct mrb_rational *p = rational_ptr(mrb, self);
- return mrb_fixnum_value(p->denominator);
+ return mrb_int_value(mrb, p->denominator);
}
static mrb_value
@@ -154,7 +154,7 @@ rational_to_i(mrb_state *mrb, mrb_value self)
if (p->denominator == 0) {
mrb_raise(mrb, mrb->eStandardError_class, "divided by 0");
}
- return mrb_fixnum_value(p->numerator / p->denominator);
+ return mrb_int_value(mrb, p->numerator / p->denominator);
}
static mrb_value

MODIFY
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
@@ -842,7 +842,7 @@ mrb_win32_basicsocket_syswrite(mrb_state *mrb, mrb_value self)
n = send(sd, RSTRING_PTR(str), (int)RSTRING_LEN(str), 0);
if (n == SOCKET_ERROR)
mrb_sys_fail(mrb, "send");
- return mrb_fixnum_value(n);
+ return mrb_int_value(mrb, n);
}
#endif
@@ -938,7 +938,7 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
#define define_const(SYM) \
do { \
- mrb_define_const(mrb, constants, #SYM, mrb_fixnum_value(SYM)); \
+ mrb_define_const(mrb, constants, #SYM, mrb_int_value(mrb, SYM)); \
} while (0)
#include "const.cstub"

MODIFY
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
@@ -938,10 +938,10 @@ retry:
s = nbuf;
if (v < 0) {
dots = 1;
- val = mrb_fix2binstr(mrb, mrb_fixnum_value(v), base);
+ val = mrb_fix2binstr(mrb, mrb_int_value(mrb, v), base);
}
else {
- val = mrb_fixnum_to_str(mrb, mrb_fixnum_value(v), base);
+ val = mrb_fixnum_to_str(mrb, mrb_int_value(mrb, v), base);
}
strncpy(++s, RSTRING_PTR(val), sizeof(nbuf)-2);
if (v < 0) {

MODIFY
mrbgems/mruby-test/driver.c
mrbgems/mruby-test/driver.c
@@ -254,7 +254,7 @@ mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src)
res_src = mrb_gv_get(mrb_src, mrb_intern_lit(mrb_src, "$" #name)); \
if (mrb_integer_p(res_src)) { \
mrb_value res_dst = mrb_gv_get(mrb_dst, mrb_intern_lit(mrb_dst, "$" #name)); \
- mrb_gv_set(mrb_dst, mrb_intern_lit(mrb_dst, "$" #name), mrb_fixnum_value(mrb_integer(res_dst) + mrb_integer(res_src))); \
+ mrb_gv_set(mrb_dst, mrb_intern_lit(mrb_dst, "$" #name), mrb_int_value(mrb_dst, mrb_integer(res_dst) + mrb_integer(res_src))); \
} \
} while (FALSE) \

MODIFY
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
@@ -205,7 +205,7 @@ typedef mrb_float mrb_sec;
#define mrb_sec_value(mrb, sec) mrb_float_value(mrb, sec)
#else
typedef mrb_int mrb_sec;
-#define mrb_sec_value(mrb, sec) mrb_fixnum_value(sec)
+#define mrb_sec_value(mrb, sec) mrb_int_value(mrb, sec)
#endif
#define MRB_TIME_T_UINT (~(time_t)0 > 0)
@@ -585,7 +585,7 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
mrb_int f;
f = tm->sec - tm2->sec;
if (tm->usec < tm2->usec) f--;
- return mrb_fixnum_value(f);
+ return mrb_int_value(mrb, f);
#endif
}
else {
@@ -873,7 +873,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self)
return mrb_float_value(mrb, (mrb_float)tm->sec);
}
#endif
- return mrb_fixnum_value((mrb_int)tm->sec);
+ return mrb_int_value(mrb, (mrb_int)tm->sec);
}
/* 15.2.19.7.26 */

MODIFY
src/enum.c
src/enum.c
@@ -18,7 +18,7 @@ enum_update_hash(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "iii", &hash, &index, &hv);
hash ^= ((uint32_t)hv << (index % 16));
- return mrb_fixnum_value(hash);
+ return mrb_int_value(mrb, hash);
}
void

MODIFY
src/kernel.c
src/kernel.c
@@ -96,7 +96,7 @@ mrb_equal_m(mrb_state *mrb, mrb_value self)
mrb_value
mrb_obj_id_m(mrb_state *mrb, mrb_value self)
{
- return mrb_fixnum_value(mrb_obj_id(self));
+ return mrb_int_value(mrb, mrb_obj_id(self));
}
static int
@@ -489,7 +489,7 @@ mrb_obj_frozen(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_obj_hash(mrb_state *mrb, mrb_value self)
{
- return mrb_fixnum_value(mrb_obj_id(self));
+ return mrb_int_value(mrb, mrb_obj_id(self));
}
/* 15.3.1.3.16 */

MODIFY
src/numeric.c
src/numeric.c
@@ -131,7 +131,7 @@ int_div(mrb_state *mrb, mrb_value xv)
if (y == 0) {
mrb_raise(mrb, E_ZERODIV_ERROR, "devided by zero");
}
- return mrb_fixnum_value(mrb_integer(xv) / y);
+ return mrb_int_value(mrb, mrb_integer(xv) / y);
}
}
@@ -988,7 +988,7 @@ int_divmod(mrb_state *mrb, mrb_value x)
mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0");
}
fixdivmod(mrb, mrb_integer(x), mrb_integer(y), &div, &mod);
- return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod));
+ return mrb_assoc_new(mrb, mrb_int_value(mrb, div), mrb_int_value(mrb, mod));
}
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
@@ -1065,12 +1065,12 @@ int_rev(mrb_state *mrb, mrb_value num)
{
mrb_int val = mrb_integer(num);
- return mrb_fixnum_value(~val);
+ return mrb_int_value(mrb, ~val);
}
#ifdef MRB_NO_FLOAT
#define bit_op(x,y,op1,op2) do {\
- return mrb_fixnum_value(mrb_integer(x) op2 mrb_integer(y));\
+ return mrb_int_value(mrb, (mrb_integer(x) op2 mrb_integer(y)));\
} while(0)
#else
static mrb_value flo_and(mrb_state *mrb, mrb_value x);
@@ -1151,7 +1151,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
goto bit_overflow;
#endif
}
- return mrb_fixnum_value(val << width);
+ return mrb_int_value(mrb, val << width);
}
else {
if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
@@ -1162,7 +1162,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
goto bit_overflow;
#endif
}
- return mrb_fixnum_value(val * ((mrb_int)1 << width));
+ return mrb_int_value(mrb, (val * ((mrb_int)1 << width)));
}
#ifndef MRB_NO_FLOAT
@@ -1178,7 +1178,7 @@ bit_overflow:
}
static mrb_value
-rshift(mrb_int val, mrb_int width)
+rshift(mrb_state *mrb, mrb_int val, mrb_int width)
{
if (width < 0) { /* mrb_int overflow */
return mrb_fixnum_value(0);
@@ -1189,7 +1189,7 @@ rshift(mrb_int val, mrb_int width)
}
return mrb_fixnum_value(0);
}
- return mrb_fixnum_value(val >> width);
+ return mrb_int_value(mrb, val >> width);
}
/* 15.2.8.3.12 */
@@ -1212,7 +1212,7 @@ int_lshift(mrb_state *mrb, mrb_value x)
val = mrb_integer(x);
if (val == 0) return x;
if (width < 0) {
- return rshift(val, -width);
+ return rshift(mrb, val, -width);
}
return lshift(mrb, val, width);
}
@@ -1239,7 +1239,7 @@ int_rshift(mrb_state *mrb, mrb_value x)
if (width < 0) {
return lshift(mrb, val, -width);
}
- return rshift(val, width);
+ return rshift(mrb, val, width);
}
/* 15.2.8.3.23 */
@@ -1292,7 +1292,7 @@ mrb_flo_to_fixnum(mrb_state *mrb, mrb_value x)
mrb_raisef(mrb, E_RANGE_ERROR, "number (%v) too big for integer", x);
}
}
- return mrb_fixnum_value(z);
+ return mrb_int_value(mrb, z);
}
#endif
@@ -1312,7 +1312,7 @@ fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y)
return mrb_float_value(mrb, (mrb_float)a + (mrb_float)b);
#endif
}
- return mrb_fixnum_value(c);
+ return mrb_int_value(mrb, c);
}
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
@@ -1368,7 +1368,7 @@ fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y)
return mrb_float_value(mrb, (mrb_float)a - (mrb_float)b);
#endif
}
- return mrb_fixnum_value(c);
+ return mrb_int_value(mrb, c);
}
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");

MODIFY
src/proc.c
src/proc.c
@@ -242,7 +242,7 @@ mrb_proc_init_copy(mrb_state *mrb, mrb_value self)
static mrb_value
proc_arity(mrb_state *mrb, mrb_value self)
{
- return mrb_fixnum_value(mrb_proc_arity(mrb_proc_ptr(self)));
+ return mrb_int_value(mrb, mrb_proc_arity(mrb_proc_ptr(self)));
}
/* 15.3.1.2.6 */

MODIFY
src/vm.c
src/vm.c
@@ -1082,16 +1082,16 @@ RETRY_TRY_BLOCK:
CASE(OP_LOADL, BB) {
switch (pool[b].tt) { /* number */
case IREP_TT_INT32:
- regs[a] = mrb_fixnum_value((mrb_int)pool[b].u.i32);
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i32);
break;
case IREP_TT_INT64:
#if defined(MRB_INT64)
- regs[a] = mrb_fixnum_value((mrb_int)pool[b].u.i64);
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i64);
break;
#else
#if defined(MRB_64BIT)
if (INT32_MIN <= pool[b].u.i64 && pool[b].u.i64 <= INT32_MAX) {
- regs[a] = mrb_fixnum_value((mrb_int)pool[b].u.i64);
+ regs[a] = mrb_int_value(mrb, (mrb_int)pool[b].u.i64);
break;
}
#endif

Use `mrb_int_value()` instead of `mrb_fixnum_value()`.

Where fixnum overflow can happen.