diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-02 04:25:11 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-02 04:25:11 +0000 |
commit | ee2ddf5411f51ea89a1569ea5d70b41cd4c6c7f2 (patch) | |
tree | 4dc6256e2e7bfe46160227e82a2efa59a40df4e7 /complex.c | |
parent | 888ddda157a3253eac9e2b8962826f55e2b8fb85 (diff) | |
download | ruby-ee2ddf5411f51ea89a1569ea5d70b41cd4c6c7f2.tar.gz |
complex.c: fix against redefining component methods
This fixes the incompatibility (maybe unintentionally) introduced by
removal of `#ifndef PRESERVE_SIGNEDZERO` guards in f_add, f_mul, and
f_sub functions in r62701. [Bug #15491] [ruby-core:90843]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r-- | complex.c | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -71,21 +71,24 @@ f_##n(VALUE x, VALUE y)\ inline static VALUE f_add(VALUE x, VALUE y) { - if (FIXNUM_ZERO_P(y)) - return x; - if (FIXNUM_ZERO_P(x)) - return y; - if (RB_INTEGER_TYPE_P(x) && UNLIKELY(rb_method_basic_definition_p(rb_cInteger, idPLUS))) { + if (FIXNUM_ZERO_P(x)) + return y; + if (FIXNUM_ZERO_P(y)) + return x; return rb_int_plus(x, y); } else if (RB_FLOAT_TYPE_P(x) && UNLIKELY(rb_method_basic_definition_p(rb_cFloat, idPLUS))) { + if (FIXNUM_ZERO_P(y)) + return x; return rb_float_plus(x, y); } else if (RB_TYPE_P(x, T_RATIONAL) && UNLIKELY(rb_method_basic_definition_p(rb_cRational, idPLUS))) { + if (FIXNUM_ZERO_P(y)) + return x; return rb_rational_plus(x, y); } @@ -120,20 +123,28 @@ f_gt_p(VALUE x, VALUE y) inline static VALUE f_mul(VALUE x, VALUE y) { - if (FIXNUM_ZERO_P(y) && RB_INTEGER_TYPE_P(x)) - return ZERO; - if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y)) - return ZERO; - if (y == ONE) return x; - if (x == ONE) return y; + if (RB_INTEGER_TYPE_P(x) && + UNLIKELY(rb_method_basic_definition_p(rb_cInteger, idMULT))) { + if (FIXNUM_ZERO_P(y)) + return ZERO; + if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y)) + return ZERO; + if (x == ONE) return y; + if (y == ONE) return x; + } + else if (UNLIKELY(rb_method_basic_definition_p(CLASS_OF(x), idMULT))) { + if (y == ONE) return x; + } return rb_funcall(x, '*', 1, y); } inline static VALUE f_sub(VALUE x, VALUE y) { - if (FIXNUM_ZERO_P(y)) + if (FIXNUM_ZERO_P(y) && + UNLIKELY(rb_method_basic_definition_p(CLASS_OF(x), idMINUS))) { return x; + } return rb_funcall(x, '-', 1, y); } |