ruby-changes:55012
From: nagachika <ko1@a...>
Date: Mon, 11 Mar 2019 21:52:04 +0900 (JST)
Subject: [ruby-changes:55012] nagachika:r67219 (ruby_2_5): merge revision(s) 67203: [Backport #15651]
nagachika 2019-03-11 21:51:59 +0900 (Mon, 11 Mar 2019) New Revision: 67219 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67219 Log: merge revision(s) 67203: [Backport #15651] numeric.c: fix infinite loop * numeric.c (int_pow): fix infinite loop in the case of y equal 1 and power of x does not overflow. [ruby-core:91734] [Bug #15651] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/ext/-test-/integer/core_ext.c branches/ruby_2_5/numeric.c branches/ruby_2_5/test/-ext-/integer/test_integer.rb branches/ruby_2_5/version.h Index: ruby_2_5/ext/-test-/integer/core_ext.c =================================================================== --- ruby_2_5/ext/-test-/integer/core_ext.c (revision 67218) +++ ruby_2_5/ext/-test-/integer/core_ext.c (revision 67219) @@ -20,10 +20,17 @@ rb_int_to_bignum(VALUE x) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/ext/-test-/integer/core_ext.c#L20 return x; } +static VALUE +positive_pow(VALUE x, VALUE y) +{ + return rb_int_positive_pow(NUM2LONG(x), NUM2ULONG(y)); +} + void Init_core_ext(VALUE klass) { rb_define_method(rb_cInteger, "bignum?", int_bignum_p, 0); rb_define_method(rb_cInteger, "fixnum?", int_fixnum_p, 0); rb_define_method(rb_cInteger, "to_bignum", rb_int_to_bignum, 0); + rb_define_method(rb_cInteger, "positive_pow", positive_pow, 1); } Index: ruby_2_5/test/-ext-/integer/test_integer.rb =================================================================== --- ruby_2_5/test/-ext-/integer/test_integer.rb (revision 67218) +++ ruby_2_5/test/-ext-/integer/test_integer.rb (revision 67219) @@ -12,4 +12,15 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/-ext-/integer/test_integer.rb#L12 assert_fixnum(FIXNUM_MAX) assert_bignum(FIXNUM_MAX+1) end + + def test_positive_pow + assert_separately(%w[-r-test-/integer], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 3) + begin; + assert_equal(1, 1.positive_pow(1)) + assert_equal(0, 0.positive_pow(1)) + assert_equal(3, 3.positive_pow(1)) + assert_equal(-3, -3.positive_pow(1)) + assert_equal(9, -3.positive_pow(2)) + end; + end end Index: ruby_2_5/numeric.c =================================================================== --- ruby_2_5/numeric.c (revision 67218) +++ ruby_2_5/numeric.c (revision 67219) @@ -3905,6 +3905,7 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/numeric.c#L3905 long z = 1; if (y == 0) return INT2FIX(1); + if (y == 1) return LONG2NUM(x); if (neg) x = -x; if (y & 1) z = x; Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 67218) +++ ruby_2_5/version.h (revision 67219) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.4" -#define RUBY_RELEASE_DATE "2019-03-08" -#define RUBY_PATCHLEVEL 143 +#define RUBY_RELEASE_DATE "2019-03-11" +#define RUBY_PATCHLEVEL 144 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 8 +#define RUBY_RELEASE_DAY 11 #include "ruby/version.h" Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 67218) +++ ruby_2_5 (revision 67219) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r67203 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/