ruby-changes:50543
From: nobu <ko1@a...>
Date: Wed, 7 Mar 2018 16:43:12 +0900 (JST)
Subject: [ruby-changes:50543] nobu:r62683 (trunk): object.c: conversions with ID
nobu 2018-03-07 16:43:07 +0900 (Wed, 07 Mar 2018) New Revision: 62683 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62683 Log: object.c: conversions with ID * object.c (rb_to_integer, rb_check_to_int): convert to Integer with method ID. Modified files: trunk/object.c Index: object.c =================================================================== --- object.c (revision 62682) +++ object.c (revision 62683) @@ -3035,15 +3035,16 @@ rb_check_convert_type_with_id(VALUE val, https://github.com/ruby/ruby/blob/trunk/object.c#L3035 return v; } +#define try_to_int(val, mid, raise) \ + convert_type_with_id(val, "Integer", mid, raise, -1) static VALUE -rb_to_integer(VALUE val, const char *method) +rb_to_integer(VALUE val, const char *method, ID mid) { VALUE v; - if (FIXNUM_P(val)) return val; - if (RB_TYPE_P(val, T_BIGNUM)) return val; - v = convert_type(val, "Integer", method, TRUE); + if (RB_INTEGER_TYPE_P(val)) return val; + v = try_to_int(val, mid, TRUE); if (!RB_INTEGER_TYPE_P(v)) { conversion_mismatch(val, "Integer", method, v); } @@ -3085,7 +3086,7 @@ rb_check_to_integer(VALUE val, const cha https://github.com/ruby/ruby/blob/trunk/object.c#L3086 VALUE rb_to_int(VALUE val) { - return rb_to_integer(val, "to_int"); + return rb_to_integer(val, "to_int", idTo_int); } /** @@ -3100,7 +3101,10 @@ rb_to_int(VALUE val) https://github.com/ruby/ruby/blob/trunk/object.c#L3101 VALUE rb_check_to_int(VALUE val) { - return rb_check_to_integer(val, "to_int"); + if (RB_INTEGER_TYPE_P(val)) return val; + val = try_to_int(val, idTo_int, FALSE); + if (RB_INTEGER_TYPE_P(val)) return val; + return Qnil; } static VALUE @@ -3134,7 +3138,7 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/object.c#L3138 } tmp = convert_type_with_id(val, "Integer", idTo_int, FALSE, -1); if (!RB_INTEGER_TYPE_P(tmp)) { - return rb_to_integer(val, "to_i"); + return rb_to_integer(val, "to_i", idTo_i); } return tmp; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/