mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* bignum.c (bignew_1): Bignum instances are frozen.
Feature #3222 * include/ruby/ruby.h: Fixnum instances are also frozen. * class.c (singleton_class_of): check Bignum before singleton cheking. * test/ruby/test_bignum.rb: add a test. * test/ruby/test_fixnum.rb: ditto. * test/ruby/marshaltestlib.rb, test/ruby/test_eval.rb, test/ruby/test_object.rb: catch up above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									5dc9855a4f
								
							
						
					
					
						commit
						f3e5f2cd75
					
				
					 9 changed files with 33 additions and 22 deletions
				
			
		
							
								
								
									
										17
									
								
								ChangeLog
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								ChangeLog
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,3 +1,20 @@
 | 
			
		|||
Sun Oct 28 08:23:16 2012  Koichi Sasada  <ko1@atdot.net>
 | 
			
		||||
 | 
			
		||||
	* bignum.c (bignew_1): Bignum instances are frozen.
 | 
			
		||||
	  Feature #3222
 | 
			
		||||
 | 
			
		||||
	* include/ruby/ruby.h: Fixnum instances are also frozen.
 | 
			
		||||
 | 
			
		||||
	* class.c (singleton_class_of): check Bignum before
 | 
			
		||||
	  singleton cheking.
 | 
			
		||||
 | 
			
		||||
	* test/ruby/test_bignum.rb: add a test.
 | 
			
		||||
 | 
			
		||||
	* test/ruby/test_fixnum.rb: ditto.
 | 
			
		||||
 | 
			
		||||
	* test/ruby/marshaltestlib.rb, test/ruby/test_eval.rb,
 | 
			
		||||
	  test/ruby/test_object.rb: catch up above changes.
 | 
			
		||||
 | 
			
		||||
Sun Oct 28 04:38:06 2012  Koichi Sasada  <ko1@atdot.net>
 | 
			
		||||
 | 
			
		||||
	* vm.c (vm_define_method): remove type and frozen checking.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								bignum.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								bignum.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -176,7 +176,7 @@ bignew_1(VALUE klass, long len, int sign)
 | 
			
		|||
	RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len);
 | 
			
		||||
	RBIGNUM(big)->as.heap.len = len;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    OBJ_FREEZE(big);
 | 
			
		||||
    return (VALUE)big;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								class.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								class.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1323,8 +1323,10 @@ singleton_class_of(VALUE obj)
 | 
			
		|||
	return klass;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
       if (BUILTIN_TYPE(obj) == T_FLOAT)
 | 
			
		||||
	enum ruby_value_type type = BUILTIN_TYPE(obj);
 | 
			
		||||
	if (type == T_FLOAT || type == T_BIGNUM) {
 | 
			
		||||
           rb_raise(rb_eTypeError, "can't define singleton");
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1133,7 +1133,7 @@ struct RBignum {
 | 
			
		|||
                        (FL_TAINT | FL_UNTRUSTED); \
 | 
			
		||||
} while (0)
 | 
			
		||||
 | 
			
		||||
#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):FLONUM_P(x)))
 | 
			
		||||
#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x))))
 | 
			
		||||
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
 | 
			
		||||
 | 
			
		||||
#if SIZEOF_INT < SIZEOF_LONG
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -178,22 +178,6 @@ module MarshalTestLib
 | 
			
		|||
    marshal_equal(0x3fff_ffff)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_fixnum_ivar
 | 
			
		||||
    o1 = 1
 | 
			
		||||
    o1.instance_eval { @iv = 2 }
 | 
			
		||||
    marshal_equal(o1) {|o| o.instance_eval { @iv }}
 | 
			
		||||
  ensure
 | 
			
		||||
    1.instance_eval { remove_instance_variable("@iv") }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_fixnum_ivar_self
 | 
			
		||||
    o1 = 1
 | 
			
		||||
    o1.instance_eval { @iv = 1 }
 | 
			
		||||
    marshal_equal(o1) {|o| o.instance_eval { @iv }}
 | 
			
		||||
  ensure
 | 
			
		||||
    1.instance_eval { remove_instance_variable("@iv") }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_float
 | 
			
		||||
    marshal_equal(-1.0)
 | 
			
		||||
    marshal_equal(0.0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -510,4 +510,8 @@ class TestBignum < Test::Unit::TestCase
 | 
			
		|||
    # this test assumes 32bit/64bit platform
 | 
			
		||||
    assert_raise(TypeError) { a = 1 << 64; def a.foo; end }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_frozen
 | 
			
		||||
    assert_equal(true, (2**100).frozen?)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -128,7 +128,7 @@ class TestEval < Test::Unit::TestCase
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  def forall_TYPE
 | 
			
		||||
    objects = [Object.new, [], nil, true, false, 77, :sym] # TODO: check
 | 
			
		||||
    objects = [Object.new, [], nil, true, false, :sym] # TODO: check
 | 
			
		||||
    objects.each do |obj|
 | 
			
		||||
      obj.instance_variable_set :@ivar, 12
 | 
			
		||||
      yield obj
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -275,4 +275,8 @@ class TestFixnum < Test::Unit::TestCase
 | 
			
		|||
  def test_singleton_method
 | 
			
		||||
    assert_raise(TypeError) { a = 1; def a.foo; end }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_frozen
 | 
			
		||||
    assert_equal(true, 1.frozen?)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,10 +62,10 @@ class TestObject < Test::Unit::TestCase
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  def test_freeze_immediate
 | 
			
		||||
    assert_equal(false, 1.frozen?)
 | 
			
		||||
    assert_equal(true, 1.frozen?)
 | 
			
		||||
    1.freeze
 | 
			
		||||
    assert_equal(true, 1.frozen?)
 | 
			
		||||
    assert_equal(false, 2.frozen?)
 | 
			
		||||
    assert_equal(true, 2.frozen?)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_nil_to_f
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue