Skip to content

Commit

Permalink
macro mrb_bool() may evaluate arg multiple times; ref #3228
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Oct 23, 2016
1 parent 7061658 commit c45ed46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down

0 comments on commit c45ed46

Please sign in to comment.