ruby-changes:51700
From: ko1 <ko1@a...>
Date: Mon, 9 Jul 2018 17:07:32 +0900 (JST)
Subject: [ruby-changes:51700] ko1:r63912 (trunk): Don't copy FL_USER* on Kernel#clone. [Bug #14847]
ko1 2018-07-09 17:07:26 +0900 (Mon, 09 Jul 2018) New Revision: 63912 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63912 Log: Don't copy FL_USER* on Kernel#clone. [Bug #14847] * object.c (mutable_obj_clone): `Kernel#clone` should not copy FL_USER* flags because they are copied unexpectedly. Unexpected copy will break internal data consistency. Modified files: trunk/object.c trunk/test/ruby/test_clone.rb Index: object.c =================================================================== --- object.c (revision 63911) +++ object.c (revision 63912) @@ -448,8 +448,6 @@ mutable_obj_clone(VALUE obj, int kwfreez https://github.com/ruby/ruby/blob/trunk/object.c#L448 VALUE clone, singleton; clone = rb_obj_alloc(rb_obj_class(obj)); - RBASIC(clone)->flags &= (FL_TAINT|FL_PROMOTED0|FL_PROMOTED1); - RBASIC(clone)->flags |= RBASIC(obj)->flags & ~(FL_PROMOTED0|FL_PROMOTED1|FL_FREEZE|FL_FINALIZE); singleton = rb_singleton_class_clone_and_attach(obj, clone); RBASIC_SET_CLASS(clone, singleton); Index: test/ruby/test_clone.rb =================================================================== --- test/ruby/test_clone.rb (revision 63911) +++ test/ruby/test_clone.rb (revision 63912) @@ -26,4 +26,39 @@ class TestClone < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_clone.rb#L26 assert_equal([M003, M002, M001], M003.ancestors) end + + def test_user_flags + assert_separately([], <<-EOS) + # + class Array + undef initialize_copy + def initialize_copy(*); end + end + x = [1, 2, 3].clone + assert_equal [], x, '[Bug #14847]' + EOS + + assert_separately([], <<-EOS) + # + class Array + undef initialize_copy + def initialize_copy(*); end + end + x = [1,2,3,4,5,6,7][1..-2].clone + x.push(1,1,1,1,1) + assert_equal [1, 1, 1, 1, 1], x, '[Bug #14847]' + EOS + + assert_separately([], <<-EOS) + # + class Hash + undef initialize_copy + def initialize_copy(*); end + end + h = {} + h.default_proc = proc { raise } + h = h.clone + assert_equal nil, h[:not_exist], '[Bug #14847]' + EOS + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/