aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-13 10:49:11 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-13 10:49:11 +0000
commit83aba0486298d61b39f3ed3492042690a889807f (patch)
tree42d060575f0931f834aa85d2493d3c9693b18a4e /object.c
parentaacd7710462142df7397618ffff4279e495f10f9 (diff)
downloadruby-83aba0486298d61b39f3ed3492042690a889807f.tar.gz
* 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
Diffstat (limited to 'object.c')
-rw-r--r--object.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/object.c b/object.c
index d999c8c313..e15d89f99b 100644
--- a/object.c
+++ b/object.c
@@ -53,7 +53,16 @@ VALUE
rb_obj_hide(VALUE obj)
{
if (!SPECIAL_CONST_P(obj)) {
- RBASIC(obj)->klass = 0;
+ RBASIC_CLEAR_CLASS(obj);
+ }
+ return obj;
+}
+
+VALUE
+rb_obj_reveal(VALUE obj, VALUE klass)
+{
+ if (!SPECIAL_CONST_P(obj)) {
+ RBASIC_SET_CLASS(obj, klass);
}
return obj;
}
@@ -62,7 +71,7 @@ VALUE
rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
{
RBASIC(obj)->flags = type;
- RBASIC(obj)->klass = klass;
+ RBASIC_SET_CLASS(obj, klass);
if (rb_safe_level() >= 3) FL_SET((obj), FL_TAINT | FL_UNTRUSTED);
return obj;
}
@@ -327,7 +336,7 @@ rb_obj_clone(VALUE obj)
}
clone = rb_obj_alloc(rb_obj_class(obj));
singleton = rb_singleton_class_clone_and_attach(obj, clone);
- RBASIC(clone)->klass = singleton;
+ RBASIC_SET_CLASS(clone, singleton);
if (FL_TEST(singleton, FL_SINGLETON)) {
rb_singleton_class_attached(singleton, clone);
}
@@ -1630,7 +1639,7 @@ rb_module_s_alloc(VALUE klass)
{
VALUE mod = rb_module_new();
- RBASIC(mod)->klass = klass;
+ RBASIC_SET_CLASS(mod, klass);
return mod;
}
@@ -1723,7 +1732,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eTypeError, "can't inherit uninitialized class");
}
}
- RCLASS_SUPER(klass) = super;
+ RCLASS_SET_SUPER(klass, super);
rb_make_metaclass(klass, RBASIC(super)->klass);
rb_class_inherited(super, klass);
rb_mod_initialize(klass);
@@ -1858,7 +1867,7 @@ rb_class_superclass(VALUE klass)
VALUE
rb_class_get_superclass(VALUE klass)
{
- return RCLASS_SUPER(klass);
+ return RCLASS_EXT(klass)->super;
}
#define id_for_setter(name, type, message) \