ruby-changes:44620
From: nobu <ko1@a...>
Date: Thu, 10 Nov 2016 19:39:57 +0900 (JST)
Subject: [ruby-changes:44620] nobu:r56693 (trunk): range.c: check if range modifiable
nobu 2016-11-10 19:39:51 +0900 (Thu, 10 Nov 2016) New Revision: 56693 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56693 Log: range.c: check if range modifiable * range.c (range_modify): frozen object cannot be modified. Modified files: trunk/range.c trunk/test/ruby/test_range.rb Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 56692) +++ test/ruby/test_range.rb (revision 56693) @@ -11,6 +11,12 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L11 assert_equal((0...2), Range.new(0, 2, true)) end + def test_frozen_initialize + r = Range.allocate + r.freeze + assert_raise(RuntimeError){r.__send__(:initialize, 1, 2)} + end + def test_range_string # XXX: Is this really the test of Range? assert_equal([], ("a" ... "a").to_a) Index: range.c =================================================================== --- range.c (revision 56692) +++ range.c (revision 56693) @@ -80,6 +80,7 @@ rb_range_new(VALUE beg, VALUE end, int e https://github.com/ruby/ruby/blob/trunk/range.c#L80 static void range_modify(VALUE range) { + rb_check_frozen(range); /* Ranges are immutable, so that they should be initialized only once. */ if (RANGE_EXCL(range) != Qnil) { rb_name_err_raise("`initialize' called twice", range, ID2SYM(idInitialize)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/