ruby-changes:48100
From: nobu <ko1@a...>
Date: Thu, 19 Oct 2017 19:58:14 +0900 (JST)
Subject: [ruby-changes:48100] nobu:r60214 (trunk): freeze Complex and Rational
nobu 2017-10-19 19:58:08 +0900 (Thu, 19 Oct 2017) New Revision: 60214 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60214 Log: freeze Complex and Rational * complex.c (nucomp_s_new_internal, nucomp_loader): Complex instances are always frozen now. [Feature #13983] * rational.c (nurat_s_new_internal, nurat_loader): Rational instances are always frozen now. [Feature #13983] Modified files: trunk/complex.c trunk/rational.c trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 60213) +++ test/ruby/test_rational.rb (revision 60214) @@ -59,7 +59,6 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L59 def test_freeze c = Rational(1) - c.freeze assert_predicate(c, :frozen?) assert_instance_of(String, c.to_s) end @@ -639,12 +638,10 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L638 def test_marshal c = Rational(1,2) - c.instance_eval{@ivar = 9} s = Marshal.dump(c) c2 = Marshal.load(s) assert_equal(c, c2) - assert_equal(9, c2.instance_variable_get(:@ivar)) assert_instance_of(Rational, c2) assert_raise(TypeError){ @@ -657,7 +654,6 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L654 bug3656 = '[ruby-core:31622]' c = Rational(1,2) - c.freeze assert_predicate(c, :frozen?) result = c.marshal_load([2,3]) rescue :fail assert_equal(:fail, result, bug3656) Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 60213) +++ test/ruby/test_complex.rb (revision 60214) @@ -75,7 +75,6 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L75 def test_freeze c = Complex(1) - c.freeze assert_predicate(c, :frozen?) assert_instance_of(String, c.to_s) end @@ -534,12 +533,10 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L533 def test_marshal c = Complex(1,2) - c.instance_eval{@ivar = 9} s = Marshal.dump(c) c2 = Marshal.load(s) assert_equal(c, c2) - assert_equal(9, c2.instance_variable_get(:@ivar)) assert_instance_of(Complex, c2) c = Complex(Rational(1,2),Rational(2,3)) @@ -551,7 +548,6 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L548 bug3656 = '[ruby-core:31622]' c = Complex(1,2) - c.freeze assert_predicate(c, :frozen?) result = c.marshal_load([2,3]) rescue :fail assert_equal(:fail, result, bug3656) Index: complex.c =================================================================== --- complex.c (revision 60213) +++ complex.c (revision 60214) @@ -298,6 +298,7 @@ nucomp_s_new_internal(VALUE klass, VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L298 RCOMPLEX_SET_REAL(obj, real); RCOMPLEX_SET_IMAG(obj, imag); + OBJ_FREEZE_RAW(obj); return (VALUE)obj; } @@ -1406,6 +1407,7 @@ nucomp_loader(VALUE self, VALUE a) https://github.com/ruby/ruby/blob/trunk/complex.c#L1407 RCOMPLEX_SET_REAL(dat, rb_ivar_get(a, id_i_real)); RCOMPLEX_SET_IMAG(dat, rb_ivar_get(a, id_i_imag)); + OBJ_FREEZE_RAW(self); return self; } Index: rational.c =================================================================== --- rational.c (revision 60213) +++ rational.c (revision 60214) @@ -410,6 +410,7 @@ nurat_s_new_internal(VALUE klass, VALUE https://github.com/ruby/ruby/blob/trunk/rational.c#L410 RRATIONAL_SET_NUM(obj, num); RRATIONAL_SET_DEN(obj, den); + OBJ_FREEZE_RAW(obj); return (VALUE)obj; } @@ -1855,6 +1856,7 @@ nurat_loader(VALUE self, VALUE a) https://github.com/ruby/ruby/blob/trunk/rational.c#L1856 nurat_canonicalize(&num, &den); RRATIONAL_SET_NUM(dat, num); RRATIONAL_SET_DEN(dat, den); + OBJ_FREEZE_RAW(self); return self; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/