ruby-changes:25296
From: ko1 <ko1@a...>
Date: Sun, 28 Oct 2012 09:04:01 +0900 (JST)
Subject: [ruby-changes:25296] ko1:r37348 (trunk): * bignum.c (bignew_1): Bignum instances are frozen.
ko1 2012-10-28 09:03:20 +0900 (Sun, 28 Oct 2012) New Revision: 37348 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37348 Log: * 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. Modified files: trunk/ChangeLog trunk/bignum.c trunk/class.c trunk/include/ruby/ruby.h trunk/test/ruby/marshaltestlib.rb trunk/test/ruby/test_bignum.rb trunk/test/ruby/test_eval.rb trunk/test/ruby/test_fixnum.rb trunk/test/ruby/test_object.rb Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 37347) +++ include/ruby/ruby.h (revision 37348) @@ -1133,7 +1133,7 @@ (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 Index: ChangeLog =================================================================== --- ChangeLog (revision 37347) +++ ChangeLog (revision 37348) @@ -1,3 +1,20 @@ +Sun Oct 28 08:23:16 2012 Koichi Sasada <ko1@a...> + + * 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@a...> * vm.c (vm_define_method): remove type and frozen checking. Index: class.c =================================================================== --- class.c (revision 37347) +++ class.c (revision 37348) @@ -1323,8 +1323,10 @@ 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) && Index: bignum.c =================================================================== --- bignum.c (revision 37347) +++ bignum.c (revision 37348) @@ -176,7 +176,7 @@ RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len); RBIGNUM(big)->as.heap.len = len; } - + OBJ_FREEZE(big); return (VALUE)big; } Index: test/ruby/marshaltestlib.rb =================================================================== --- test/ruby/marshaltestlib.rb (revision 37347) +++ test/ruby/marshaltestlib.rb (revision 37348) @@ -178,22 +178,6 @@ 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) Index: test/ruby/test_bignum.rb =================================================================== --- test/ruby/test_bignum.rb (revision 37347) +++ test/ruby/test_bignum.rb (revision 37348) @@ -510,4 +510,8 @@ # 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 Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 37347) +++ test/ruby/test_object.rb (revision 37348) @@ -62,10 +62,10 @@ 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 Index: test/ruby/test_eval.rb =================================================================== --- test/ruby/test_eval.rb (revision 37347) +++ test/ruby/test_eval.rb (revision 37348) @@ -128,7 +128,7 @@ 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 Index: test/ruby/test_fixnum.rb =================================================================== --- test/ruby/test_fixnum.rb (revision 37347) +++ test/ruby/test_fixnum.rb (revision 37348) @@ -275,4 +275,8 @@ def test_singleton_method assert_raise(TypeError) { a = 1; def a.foo; end } end + + def test_frozen + assert_equal(true, 1.frozen?) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/