From f9727c12cc8fbc5f752f5983be1f14bb976e5a13 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 17 May 2016 06:53:48 +0000 Subject: [Feature #12005] Unify Fixnum and Bignum into Integer * [Feature #12005] Unify Fixnum and Bignum into Integer * include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums. * insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG. * vm_core.h: Ditto. * vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead of FIXNUM_REDEFINED_OP_FLAG. * vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of rb_cFixnum and rb_cBignum. (C): Use Integer instead of Fixnum and Bignum. * numeric.c (fix_succ): Removed. (Init_Numeric): Define Fixnum as Integer. * bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum. (rb_int_coerce): replaced from rb_big_coerce and return fixnums as-is. (Init_Bignum): Define Bignum as Integer. Don't define ===. * error.c (builtin_class_name): Return "Integer" for fixnums. * sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum. * ext/-test-/testutil: New directory to test. Currently it provides utilities for fixnum and bignum. * ext/json/generator/generator.c: Define mInteger_to_json. * lib/mathn.rb (Fixnum#/): Redefinition removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/num2int/test_num2int.rb | 4 ++-- test/-ext-/typeddata/test_typeddata.rb | 2 +- test/lib/test/unit.rb | 1 + test/lib/test/unit/assertions.rb | 6 ++++-- test/ruby/test_bignum.rb | 24 ++++++++++++------------ test/ruby/test_hash.rb | 2 +- test/ruby/test_integer.rb | 14 -------------- test/ruby/test_numeric.rb | 2 +- test/ruby/test_optimization.rb | 10 +++++----- test/ruby/test_regexp.rb | 2 +- test/ruby/test_settracefunc.rb | 16 ++++++++-------- 11 files changed, 36 insertions(+), 47 deletions(-) (limited to 'test') diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb index 5f1f807565..da3bf97ecd 100644 --- a/test/-ext-/num2int/test_num2int.rb +++ b/test/-ext-/num2int/test_num2int.rb @@ -104,7 +104,7 @@ class TestNum2int < Test::Unit::TestCase end def assert_fix2i_success(type, num, result=num) - return if !num.kind_of?(Fixnum) + return if !num.fixnum? func = "FIX2#{type}".upcase assert_fix2i_success_internal(result.to_s, func, num) end @@ -116,7 +116,7 @@ class TestNum2int < Test::Unit::TestCase end def assert_fix2i_error(type, num) - return if !num.kind_of?(Fixnum) + return if !num.fixnum? func = "FIX2#{type}".upcase assert_num2i_error_internal(func, num) end diff --git a/test/-ext-/typeddata/test_typeddata.rb b/test/-ext-/typeddata/test_typeddata.rb index 6f649ca08f..daeda7611a 100644 --- a/test/-ext-/typeddata/test_typeddata.rb +++ b/test/-ext-/typeddata/test_typeddata.rb @@ -10,7 +10,7 @@ class Test_TypedData < Test::Unit::TestCase assert_raise_with_message(TypeError, "wrong argument type Symbol (expected typed_data)") {Bug::TypedData.check(:e)} - assert_raise_with_message(TypeError, "wrong argument type Fixnum (expected typed_data)") {Bug::TypedData.check(0)} + assert_raise_with_message(TypeError, "wrong argument type Integer (expected typed_data)") {Bug::TypedData.check(0)} assert_raise_with_message(TypeError, "wrong argument type String (expected typed_data)") {Bug::TypedData.check("a")} diff --git a/test/lib/test/unit.rb b/test/lib/test/unit.rb index d34e11afa7..df7070e3fc 100644 --- a/test/lib/test/unit.rb +++ b/test/lib/test/unit.rb @@ -8,6 +8,7 @@ require 'test/unit/assertions' require_relative '../envutil' require 'test/unit/testcase' require 'optparse' +require '-test-/testutil' # See Test::Unit module Test diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 1df3453bc6..4e30de1be0 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -772,11 +772,13 @@ eom end def assert_fixnum(v, msg=nil) - assert_instance_of(Fixnum, v, msg) + assert_instance_of(Integer, v, msg) + assert_predicate(v, :fixnum?, msg) end def assert_bignum(v, msg=nil) - assert_instance_of(Bignum, v, msg) + assert_instance_of(Integer, v, msg) + assert_predicate(v, :bignum?, msg) end class << (AssertFile = Struct.new(:failure_message).new) diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 762368fda4..39f47ac6bb 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -16,17 +16,17 @@ class TestBignum < Test::Unit::TestCase end BIGNUM_MIN_BITS = n - T_ZERO = b.coerce(0).first - T_ONE = b.coerce(1).first - T_MONE = b.coerce(-1).first - T31 = b.coerce(2**31).first # 2147483648 - T31P = b.coerce(T31 - 1).first # 2147483647 - T32 = b.coerce(2**32).first # 4294967296 - T32P = b.coerce(T32 - 1).first # 4294967295 - T64 = b.coerce(2**64).first # 18446744073709551616 - T64P = b.coerce(T64 - 1).first # 18446744073709551615 - T1024 = b.coerce(2**1024).first - T1024P = b.coerce(T1024 - 1).first + T_ZERO = 0.to_bignum + T_ONE = 1.to_bignum + T_MONE = (-1).to_bignum + T31 = (2**31).to_bignum # 2147483648 + T31P = (T31 - 1).to_bignum # 2147483647 + T32 = (2**32).to_bignum # 4294967296 + T32P = (T32 - 1).to_bignum # 4294967295 + T64 = (2**64).to_bignum # 18446744073709551616 + T64P = (T64 - 1).to_bignum # 18446744073709551615 + T1024 = (2**1024).to_bignum + T1024P = (T1024 - 1).to_bignum def setup @verbose = $VERBOSE @@ -656,7 +656,7 @@ class TestBignum < Test::Unit::TestCase end def test_too_big_to_s - if (big = 2**31-1).is_a?(Fixnum) + if (big = 2**31-1).fixnum? return end assert_raise_with_message(RangeError, /too big to convert/) {(1 << big).to_s} diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 99231c73b2..6a8e7f0423 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -826,7 +826,7 @@ class TestHash < Test::Unit::TestCase def test_create assert_equal({1=>2, 3=>4}, @cls[[[1,2],[3,4]]]) assert_raise(ArgumentError) { Hash[0, 1, 2] } - assert_warning(/wrong element type Fixnum at 1 /) {@cls[[[1, 2], 3]]} + assert_warning(/wrong element type Integer at 1 /) {@cls[[[1, 2], 3]]} bug5406 = '[ruby-core:39945]' assert_raise(ArgumentError, bug5406) { @cls[[[1, 2], [3, 4, 5]]] } assert_equal({1=>2, 3=>4}, @cls[1,2,3,4]) diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 12ada1709e..e493a7546d 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -109,20 +109,6 @@ class TestInteger < Test::Unit::TestCase def test_succ assert_equal(2, 1.send(:succ)) - - Fixnum.class_eval do - alias succ_bak succ - remove_method :succ - end - - assert_equal(2, 1.succ) - assert_equal(4294967297, 4294967296.succ) - - ensure - Fixnum.class_eval do - alias succ succ_bak - remove_method :succ_bak - end end def test_chr diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 0463462d1a..c2a2e001b8 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -28,7 +28,7 @@ class TestNumeric < Test::Unit::TestCase assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"} bug10711 = '[ruby-core:67405] [Bug #10711]' - exp = "1.2 can't be coerced into Fixnum" + exp = "1.2 can't be coerced into Integer" assert_raise_with_message(TypeError, exp, bug10711) { 1 & 1.2 } end diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 8fd9e208e5..3b5e24f980 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -29,7 +29,7 @@ class TestRubyOptimization < Test::Unit::TestCase assert_bignum FIXNUM_MAX + 1 assert_equal 21, 10 + 11 - assert_redefine_method('Fixnum', '+', 'assert_equal 11, 10 + 11') + assert_redefine_method('Integer', '+', 'assert_equal 11, 10 + 11') end def test_fixnum_minus @@ -38,22 +38,22 @@ class TestRubyOptimization < Test::Unit::TestCase assert_bignum FIXNUM_MIN - 1 assert_equal 5, 8 - 3 - assert_redefine_method('Fixnum', '-', 'assert_equal 3, 8 - 3') + assert_redefine_method('Integer', '-', 'assert_equal 3, 8 - 3') end def test_fixnum_mul assert_equal 15, 3 * 5 - assert_redefine_method('Fixnum', '*', 'assert_equal 5, 3 * 5') + assert_redefine_method('Integer', '*', 'assert_equal 5, 3 * 5') end def test_fixnum_div assert_equal 3, 15 / 5 - assert_redefine_method('Fixnum', '/', 'assert_equal 5, 15 / 5') + assert_redefine_method('Integer', '/', 'assert_equal 5, 15 / 5') end def test_fixnum_mod assert_equal 1, 8 % 7 - assert_redefine_method('Fixnum', '%', 'assert_equal 7, 8 % 7') + assert_redefine_method('Integer', '%', 'assert_equal 7, 8 % 7') end def test_float_plus diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 24ececcbf4..1eb7e24b8c 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1013,7 +1013,7 @@ class TestRegexp < Test::Unit::TestCase def test_error_message_on_failed_conversion bug7539 = '[ruby-core:50733]' assert_equal false, /x/=== 42 - assert_raise_with_message(TypeError, 'no implicit conversion of Fixnum into String', bug7539) { + assert_raise_with_message(TypeError, 'no implicit conversion of Integer into String', bug7539) { Regexp.quote(42) } end diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 018c0062c3..3132636e18 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -35,9 +35,9 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["line", 4, __method__, self.class], events.shift) - assert_equal(["c-call", 4, :+, Fixnum], + assert_equal(["c-call", 4, :+, Integer], events.shift) - assert_equal(["c-return", 4, :+, Fixnum], + assert_equal(["c-return", 4, :+, Integer], events.shift) assert_equal(["line", 5, __method__, self.class], events.shift) @@ -73,9 +73,9 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["line", 5, :add, self.class], events.shift) - assert_equal(["c-call", 5, :+, Fixnum], + assert_equal(["c-call", 5, :+, Integer], events.shift) - assert_equal(["c-return", 5, :+, Fixnum], + assert_equal(["c-return", 5, :+, Integer], events.shift) assert_equal(["return", 6, :add, self.class], events.shift) @@ -353,8 +353,8 @@ class TestSetTraceFunc < Test::Unit::TestCase ["c-return", 8, :new, Class], ["call", 4, :foo, ThreadTraceInnerClass], ["line", 5, :foo, ThreadTraceInnerClass], - ["c-call", 5, :+, Fixnum], - ["c-return", 5, :+, Fixnum], + ["c-call", 5, :+, Integer], + ["c-return", 5, :+, Integer], ["return", 6, :foo, ThreadTraceInnerClass], ["line", 9, __method__, self.class], ["c-call", 9, :set_trace_func, Thread]].each do |e| @@ -768,10 +768,10 @@ class TestSetTraceFunc < Test::Unit::TestCase # pp events # expected_events = [[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], - [:c_call, :times, Integer, Fixnum, nil], + [:c_call, :times, Integer, Integer, nil], [:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 3], - [:c_return, :times, Integer, Fixnum, 1], + [:c_return, :times, Integer, Integer, 1], [:call, :method_for_test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 4], -- cgit v1.2.3