From 1e27eda2fa313865bda1246175b3d6ebfe8cc533 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 19 Sep 2013 05:30:02 +0000 Subject: [PATCH] * include/ruby/ruby.h: make Symbol objects frozen. [Feature #8906] I want to freeze this good day, too. * test/ruby/test_eval.rb: catch up this change. * test/ruby/test_symbol.rb: add a test to check frozen symbols. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ include/ruby/ruby.h | 2 +- test/ruby/test_eval.rb | 2 +- test/ruby/test_symbol.rb | 8 ++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ca1e73ba3..ac58fbac8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Sep 19 14:12:02 2013 Koichi Sasada + + * include/ruby/ruby.h: make Symbol objects frozen. + [Feature #8906] + I want to freeze this good day, too. + + * test/ruby/test_eval.rb: catch up this change. + + * test/ruby/test_symbol.rb: add a test to check frozen symbols. + Thu Sep 19 09:11:33 2013 Eric Hodel * NEWS: Update for RDoc 4.1.0.preview.1 and RubyGems 2.2.0.preview.1 diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 30033023bb..cb432538b1 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1247,7 +1247,7 @@ struct RBignum { RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT; \ } while (0) -#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x)))) +#define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x)||SYMBOL_P(x)))) #define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE) #if USE_RGENGC diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb index edbda38818..cba9ce42f8 100644 --- a/test/ruby/test_eval.rb +++ b/test/ruby/test_eval.rb @@ -128,7 +128,7 @@ class TestEval < Test::Unit::TestCase end def forall_TYPE - objects = [Object.new, [], nil, true, false, :sym] # TODO: check + objects = [Object.new, [], nil, true, false] # TODO: check objects.each do |obj| obj.instance_variable_set :@ivar, 12 yield obj diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 214158e864..7f261b68bb 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -198,4 +198,12 @@ class TestSymbol < Test::Unit::TestCase def test_singleton_method assert_raise(TypeError) { a = :foo; def a.foo; end } end + + def test_frozen_symbol + assert_equal(true, :foo.frozen?) + assert_equal(true, :each.frozen?) + assert_equal(true, :+.frozen?) + assert_equal(true, "foo#{Time.now.to_i}".to_sym.frozen?) + assert_equal(true, :foo.to_sym.frozen?) + end end