From 83aba0486298d61b39f3ed3492042690a889807f Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 13 May 2013 10:49:11 +0000 Subject: * include/ruby/ruby.h: constify RBasic::klass and add RBASIC_CLASS(obj) macro which returns a class of `obj'. This change is a part of RGENGC branch [ruby-trunk - Feature #8339]. * object.c: add new function rb_obj_reveal(). This function reveal interal (hidden) object by rb_obj_hide(). Note that do not change class before and after hiding. Only permitted example is: klass = RBASIC_CLASS(obj); rb_obj_hide(obj); .... rb_obj_reveal(obj, klass); TODO: API design. rb_obj_reveal() should be replaced with others. TODO: modify constified variables using cast may be harmful for compiler's analysis and optimizaton. Any idea to prohibt inserting RBasic::klass directly? If rename RBasic::klass and force to use RBASIC_CLASS(obj), then all codes such as `RBASIC(obj)->klass' will be compilation error. Is it acceptable? (We have similar experience at Ruby 1.9, for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)". * internal.h: add some macros. * RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal object. * RBASIC_SET_CLASS(obj, cls) set RBasic::klass. * RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS without write barrier (planned). * RCLASS_SET_SUPER(a, b) set super class of a. * array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c, file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c, parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c, string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c: Use above macros and functions to access RBasic::klass. * ext/coverage/coverage.c, ext/readline/readline.c, ext/socket/ancdata.c, ext/socket/init.c, * ext/zlib/zlib.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 11e974ea32..b6adfefaea 100644 --- a/string.c +++ b/string.c @@ -519,7 +519,7 @@ rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, olen = len; econv_wrapper = rb_obj_alloc(rb_cEncodingConverter); - RBASIC(econv_wrapper)->klass = 0; + RBASIC_CLEAR_CLASS(econv_wrapper); ec = rb_econv_open_opts(from->name, to->name, ecflags, ecopts); if (!ec) return str; DATA_PTR(econv_wrapper) = ec; @@ -1446,7 +1446,7 @@ rb_str_associate(VALUE str, VALUE add) RESIZE_CAPA(str, RSTRING_LEN(str)); } FL_SET(str, STR_ASSOC); - RBASIC(add)->klass = 0; + RBASIC_CLEAR_CLASS(add); RSTRING(str)->as.heap.aux.shared = add; } } @@ -3931,7 +3931,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) rb_str_shared_replace(str, dest); } else { - RBASIC(dest)->klass = rb_obj_class(str); + RBASIC_SET_CLASS(dest, rb_obj_class(str)); OBJ_INFECT(dest, str); str = dest; } -- cgit v1.2.3