summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-08 05:34:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-08 05:34:31 +0000
commit7c072b35d18391b9a1f848c6adc707c3ebbb1791 (patch)
treeeba43ccce1dc604689203e8a205f1c1f4bdc9052 /class.c
parent97cd982a3e9fb4691af3dc63fdd0c37720def513 (diff)
class.c: always clear tables first
* 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/trunk@45874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/class.c b/class.c
index 8ebc711daa..02a9e62dfd 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);
}