ruby-changes:63256
From: Nobuyoshi <ko1@a...>
Date: Fri, 2 Oct 2020 23:02:50 +0900 (JST)
Subject: [ruby-changes:63256] dd77796f1c (master): Hoisted out ensure_cmp which checks the comparison succeeded
https://git.ruby-lang.org/ruby.git/commit/?id=dd77796f1c From dd77796f1c8105355787c67007c801f063ac9d86 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 2 Oct 2020 21:30:07 +0900 Subject: Hoisted out ensure_cmp which checks the comparison succeeded diff --git a/numeric.c b/numeric.c index a767c12..4a61d64 100644 --- a/numeric.c +++ b/numeric.c @@ -467,17 +467,23 @@ rb_num_coerce_cmp(VALUE x, VALUE y, ID func) https://github.com/ruby/ruby/blob/trunk/numeric.c#L467 return Qnil; } +static VALUE +ensure_cmp(VALUE c, VALUE x, VALUE y) +{ + if (NIL_P(c)) rb_cmperr(x, y); + return c; +} + VALUE rb_num_coerce_relop(VALUE x, VALUE y, ID func) { - VALUE c, x0 = x, y0 = y; + VALUE x0 = x, y0 = y; - if (!do_coerce(&x, &y, FALSE) || - NIL_P(c = rb_funcall(x, func, 1, y))) { + if (!do_coerce(&x, &y, FALSE)) { rb_cmperr(x0, y0); - return Qnil; /* not reached */ + UNREACHABLE_RETURN(Qnil); } - return c; + return ensure_cmp(rb_funcall(x, func, 1, y), x0, y0); } NORETURN(static VALUE num_sadded(VALUE x, VALUE name)); @@ -1518,9 +1524,7 @@ flo_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1524 MJIT_FUNC_EXPORTED int rb_float_cmp(VALUE x, VALUE y) { - VALUE c = flo_cmp(x, y); - if (NIL_P(c)) rb_cmperr(x, y); - return NUM2INT(c); + return NUM2INT(ensure_cmp(flo_cmp(x, y), x, y)); } /* @@ -5093,7 +5097,7 @@ int_upto(VALUE from, VALUE to) https://github.com/ruby/ruby/blob/trunk/numeric.c#L5097 rb_yield(i); i = rb_funcall(i, '+', 1, INT2FIX(1)); } - if (NIL_P(c)) rb_cmperr(i, to); + ensure_cmp(c, i, to); } return from; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/