diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-14 09:23:54 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-14 09:23:54 +0000 |
commit | 87a120fbdc25544135e8d625e8dc11950b7245a3 (patch) | |
tree | c23668533bf769b504a5d4262a8b5f4e00564acc /variable.c | |
parent | 4dd06525612585fc592abb935b2ac6c74c908e1f (diff) |
* class.c, include/ruby/ruby.h: add write barriers for T_CLASS,
T_MODULE, T_ICLASS.
* constant.h: constify rb_const_entry_t::value and file to detect
assignment.
* variable.c, internal.h (rb_st_insert_id_and_value, rb_st_copy):
added. update table with write barrier.
* method.h: constify some variables to detect assignment.
* object.c (init_copy): add WBs.
* variable.c: ditto.
* vm_method.c (rb_add_method): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/variable.c b/variable.c index 8f2184742c..749d928b17 100644 --- a/variable.c +++ b/variable.c @@ -143,7 +143,8 @@ find_class_path(VALUE klass, ID preferred) if (!RCLASS_IV_TBL(klass)) { RCLASS_IV_TBL(klass) = st_init_numtable(); } - st_insert(RCLASS_IV_TBL(klass), (st_data_t)classpath, arg.path); + rb_st_insert_id_and_value(klass, RCLASS_IV_TBL(klass), (st_data_t)classpath, arg.path); + st_delete(RCLASS_IV_TBL(klass), &tmp, 0); return arg.path; } @@ -1184,8 +1185,7 @@ rb_ivar_set(VALUE obj, ID id, VALUE val) case T_CLASS: case T_MODULE: if (!RCLASS_IV_TBL(obj)) RCLASS_IV_TBL(obj) = st_init_numtable(); - st_insert(RCLASS_IV_TBL(obj), (st_data_t)id, val); - OBJ_WRITTEN(obj, Qundef, val); + rb_st_insert_id_and_value(obj, RCLASS_IV_TBL(obj), (st_data_t)id, val); break; default: generic: @@ -2180,8 +2180,8 @@ rb_const_set(VALUE klass, ID id, VALUE val) ce = ALLOC(rb_const_entry_t); ce->flag = visibility; - ce->value = val; - ce->file = rb_sourcefilename(); + OBJ_WRITE(klass, (VALUE *)&ce->value, val); + OBJ_WRITE(klass, (VALUE *)&ce->file, rb_sourcefilename()); ce->line = rb_sourceline(); st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce); @@ -2339,7 +2339,7 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) RCLASS_IV_TBL(target) = st_init_numtable(); } - st_insert(RCLASS_IV_TBL(target), (st_data_t)id, (st_data_t)val); + rb_st_insert_id_and_value(target, RCLASS_IV_TBL(target), (st_data_t)id, (st_data_t)val); } VALUE @@ -2576,3 +2576,27 @@ rb_iv_set(VALUE obj, const char *name, VALUE val) return rb_ivar_set(obj, id, val); } + +/* tbl = xx(obj); tbl[key] = value; */ +int +rb_st_insert_id_and_value(VALUE obj, st_table *tbl, ID key, VALUE value) +{ + int result = st_insert(tbl, (st_data_t)key, (st_data_t)value); + OBJ_WRITTEN(obj, Qundef, value); + return result; +} + +static int +tbl_copy_i(st_data_t key, st_data_t value, st_data_t data) +{ + OBJ_WRITTEN((VALUE)data, Qundef, (VALUE)value); + return ST_CONTINUE; +} + +st_table * +rb_st_copy(VALUE obj, struct st_table *orig_tbl) +{ + st_table *new_tbl = st_copy(orig_tbl); + st_foreach(new_tbl, tbl_copy_i, (st_data_t)obj); + return new_tbl; +} |