Permalink
Browse files

macro mrb_bool() may evaluate arg multiple times; ref #3228

  • Loading branch information...
matz committed Oct 23, 2016
1 parent 7061658 commit c45ed46f28b2d73aa36eeb0539cb0f3bc173b528
Showing with 7 additions and 6 deletions.
  1. +3 −2 src/kernel.c
  2. +4 −4 src/range.c
View
@@ -960,10 +960,11 @@ obj_respond_to(mrb_state *mrb, mrb_value self)
if (!respond_to_p) {
rtm_id = mrb_intern_lit(mrb, "respond_to_missing?");
if (basic_obj_respond_to(mrb, self, rtm_id, !priv)) {
mrb_value args[2];
mrb_value args[2], v;
args[0] = mid;
args[1] = mrb_bool_value(priv);
return mrb_bool_value(mrb_bool(mrb_funcall_argv(mrb, self, rtm_id, 2, args)));
v = mrb_funcall_argv(mrb, self, rtm_id, 2, args);
return mrb_bool_value(mrb_bool(v));
}
}
return mrb_bool_value(respond_to_p);
View
@@ -152,7 +152,7 @@ mrb_range_eq(mrb_state *mrb, mrb_value range)
{
struct RRange *rr;
struct RRange *ro;
mrb_value obj;
mrb_value obj, v1, v2;
mrb_get_args(mrb, "o", &obj);
@@ -163,9 +163,9 @@ mrb_range_eq(mrb_state *mrb, mrb_value range)
rr = mrb_range_ptr(range);
ro = mrb_range_ptr(obj);
if (!mrb_bool(mrb_funcall(mrb, rr->edges->beg, "==", 1, ro->edges->beg)) ||
!mrb_bool(mrb_funcall(mrb, rr->edges->end, "==", 1, ro->edges->end)) ||
rr->excl != ro->excl) {
v1 = mrb_funcall(mrb, rr->edges->beg, "==", 1, ro->edges->beg);
v2 = mrb_funcall(mrb, rr->edges->end, "==", 1, ro->edges->end);
if (!mrb_bool(v1) || !mrb_bool(v2) || rr->excl != ro->excl) {
return mrb_false_value();
}
return mrb_true_value();

0 comments on commit c45ed46

Please sign in to comment.