summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-22 17:52:26 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-22 17:52:26 +0000
commit9f982bd59d6e3e5e4c2c5ca20bdef79df4f8b5c0 (patch)
tree39668290bde4b4a6382019150cc95248aef71c86
parent07ac36ada5a486023593d129b54be836923cfa4d (diff)
merge revision(s) r45874: [Backport #9813]
* class.c (rb_mod_init_copy): always clear instance variable, constant and method tables first, regardless the source tables. [ruby-dev:48182] [Bug #9813] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--class.c22
-rw-r--r--test/ruby/test_module.rb19
-rw-r--r--version.h2
4 files changed, 39 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index e95a2c6e77..dfc225455a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Jun 23 02:46:14 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * class.c (rb_mod_init_copy): always clear instance variable,
+ constant and method tables first, regardless the source tables.
+ [ruby-dev:48182] [Bug #9813]
+
Mon Jun 23 02:36:04 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* thread.c (thread_start_func_2): stop if forked in a sub-thread,
diff --git a/class.c b/class.c
index e4ccbc9fc1..de5323a69b 100644
--- a/class.c
+++ b/class.c
@@ -328,12 +328,21 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
}
RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig));
RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
+ if (RCLASS_IV_TBL(clone)) {
+ st_free_table(RCLASS_IV_TBL(clone));
+ RCLASS_IV_TBL(clone) = 0;
+ }
+ if (RCLASS_CONST_TBL(clone)) {
+ rb_free_const_table(RCLASS_CONST_TBL(clone));
+ RCLASS_CONST_TBL(clone) = 0;
+ }
+ if (RCLASS_M_TBL_WRAPPER(clone)) {
+ rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
+ RCLASS_M_TBL_WRAPPER(clone) = 0;
+ }
if (RCLASS_IV_TBL(orig)) {
st_data_t id;
- if (RCLASS_IV_TBL(clone)) {
- st_free_table(RCLASS_IV_TBL(clone));
- }
RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig));
CONST_ID(id, "__tmp_classpath__");
st_delete(RCLASS_IV_TBL(clone), &id, 0);
@@ -344,18 +353,13 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
}
if (RCLASS_CONST_TBL(orig)) {
struct clone_const_arg arg;
- if (RCLASS_CONST_TBL(clone)) {
- rb_free_const_table(RCLASS_CONST_TBL(clone));
- }
+
RCLASS_CONST_TBL(clone) = st_init_numtable();
arg.klass = clone;
arg.tbl = RCLASS_CONST_TBL(clone);
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
}
if (RCLASS_M_TBL(orig)) {
- if (RCLASS_M_TBL_WRAPPER(clone)) {
- rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
- }
RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
}
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index ca453fa5eb..372a2d4ca5 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -375,6 +375,25 @@ class TestModule < Test::Unit::TestCase
assert_equal(:ok, Object.new.extend(m).foo, bug9535)
end
+ def test_initialize_copy_empty
+ bug9813 = '[ruby-dev:48182] [Bug #9813]'
+ m = Module.new do
+ def x
+ end
+ const_set(:X, 1)
+ @x = 2
+ end
+ assert_equal([:x], m.instance_methods)
+ assert_equal([:@x], m.instance_variables)
+ assert_equal([:X], m.constants)
+ m.module_eval do
+ initialize_copy(Module.new)
+ end
+ assert_empty(m.instance_methods, bug9813)
+ assert_empty(m.instance_variables, bug9813)
+ assert_empty(m.constants, bug9813)
+ end
+
def test_dup
bug6454 = '[ruby-core:45132]'
diff --git a/version.h b/version.h
index 2eadc6240c..257b88386a 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.2"
#define RUBY_RELEASE_DATE "2014-06-23"
-#define RUBY_PATCHLEVEL 136
+#define RUBY_PATCHLEVEL 137
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 6