From bc1827e8825c558bcda14a214280caf83dc1215b Mon Sep 17 00:00:00 2001 From: eregon Date: Tue, 25 Apr 2017 11:42:20 +0000 Subject: no longer rescue exceptions in numeric comparison operations * numeric.c (do_coerce): no more error hiding. * test/ruby/test_numeric.rb: follow the change. [Feature #7688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index ad7c984241..dda44c0a77 100644 --- a/numeric.c +++ b/numeric.c @@ -432,13 +432,6 @@ num_coerce(VALUE x, VALUE y) return rb_assoc_new(y, x); } -static VALUE -coerce_body(VALUE arg) -{ - VALUE *x = (VALUE *)arg; - return rb_funcall(x[1], id_coerce, 1, x[0]); -} - NORETURN(static void coerce_failed(VALUE x, VALUE y)); static void coerce_failed(VALUE x, VALUE y) @@ -453,14 +446,6 @@ coerce_failed(VALUE x, VALUE y) y, rb_obj_class(x)); } -static VALUE -coerce_rescue(VALUE arg, VALUE errinfo) -{ - VALUE *x = (VALUE *)arg; - coerce_failed(x[0], x[1]); - return Qnil; /* dummy */ -} - static VALUE coerce_rescue_quiet(VALUE arg, VALUE errinfo) { @@ -470,33 +455,18 @@ coerce_rescue_quiet(VALUE arg, VALUE errinfo) static int do_coerce(VALUE *x, VALUE *y, int err) { - VALUE ary; - VALUE a[2]; - - a[0] = *x; a[1] = *y; - - if (!rb_respond_to(*y, id_coerce)) { + VALUE ary = rb_check_funcall(*y, id_coerce, 1, x); + if (ary == Qundef) { if (err) { coerce_failed(*x, *y); } return FALSE; } - - ary = rb_rescue(coerce_body, (VALUE)a, err ? coerce_rescue : coerce_rescue_quiet, (VALUE)a); - if (ary == Qundef) { - rb_warn("Numerical comparison operators will no more rescue exceptions of #coerce"); - rb_warn("in the next release. Return nil in #coerce if the coercion is impossible."); + if (!err && NIL_P(ary)) { return FALSE; } if (!RB_TYPE_P(ary, T_ARRAY) || RARRAY_LEN(ary) != 2) { - if (err) { - rb_raise(rb_eTypeError, "coerce must return [x, y]"); - } - else if (!NIL_P(ary)) { - rb_warn("Bad return value for #coerce, called by numerical comparison operators."); - rb_warn("#coerce must return [x, y]. The next release will raise an error for this."); - } - return FALSE; + rb_raise(rb_eTypeError, "coerce must return [x, y]"); } *x = RARRAY_AREF(ary, 0); -- cgit v1.2.3