summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-10 20:18:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-10 20:18:39 +0000
commit5915dc245e5efac34d676ad29ebd38d6b46f16cf (patch)
tree96a07496fbd0e748f38fd6d178fa5ffda1bd373e
parent399bb7e73953bc7fbeb74e2712d931f44d7553b8 (diff)
* class.c (rb_make_metaclass): [new]
* class.c (rb_define_class_id): use rb_make_metaclass(), don't call Class#inherited hook. * class.c (rb_class_inherited): [new] * class.c (rb_define_class): call Class#inherited hook here. * class.c (rb_define_class_under): ditto after class path is set. * class.c (rb_singleton_class): use rb_make_metaclass(). * eval.c (rb_eval): same as rb_define_class_under(). * intern.h: prototypes of rb_make_metaclass() and rb_class_inherited(). * object.c (rb_class_s_new): use rb_make_metaclass() and rb_class_inherited(). * object.c (Init_Object): use rb_make_metaclass(). * struct.c (make_struct): use rb_class_inherited(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog27
-rw-r--r--class.c30
-rw-r--r--eval.c3
-rw-r--r--intern.h2
-rw-r--r--object.c15
-rw-r--r--struct.c1
6 files changed, 59 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 29a847a..17b0827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+Fri Jan 11 05:06:25 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * class.c (rb_make_metaclass): [new]
+
+ * class.c (rb_define_class_id): use rb_make_metaclass(), don't
+ call Class#inherited hook.
+
+ * class.c (rb_class_inherited): [new]
+
+ * class.c (rb_define_class): call Class#inherited hook here.
+
+ * class.c (rb_define_class_under): ditto after class path is set.
+
+ * class.c (rb_singleton_class): use rb_make_metaclass().
+
+ * eval.c (rb_eval): same as rb_define_class_under().
+
+ * intern.h: prototypes of rb_make_metaclass() and
+ rb_class_inherited().
+
+ * object.c (rb_class_s_new): use rb_make_metaclass() and
+ rb_class_inherited().
+
+ * object.c (Init_Object): use rb_make_metaclass().
+
+ * struct.c (make_struct): use rb_class_inherited().
+
Thu Jan 10 19:15:15 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* eval.c (rb_add_method): should clear cache by id always.
diff --git a/class.c b/class.c
index 238c3b3..070b413 100644
--- a/class.c
+++ b/class.c
@@ -142,6 +142,16 @@ rb_singleton_class_attached(klass, obj)
}
VALUE
+rb_make_metaclass(obj, klass)
+ VALUE obj, klass;
+{
+ klass = rb_singleton_class_new(klass);
+ RBASIC(obj)->klass = klass;
+ rb_singleton_class_attached(klass, obj);
+ return klass;
+}
+
+VALUE
rb_define_class_id(id, super)
ID id;
VALUE super;
@@ -151,15 +161,19 @@ rb_define_class_id(id, super)
if (!super) super = rb_cObject;
klass = rb_class_new(super);
rb_name_class(klass, id);
- /* make metaclass */
- RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass);
- rb_singleton_class_attached(RBASIC(klass)->klass, klass);
- rb_funcall(super, rb_intern("inherited"), 1, klass);
+ rb_make_metaclass(klass, RBASIC(super)->klass);
return klass;
}
VALUE
+rb_class_inherited(super, klass)
+ VALUE super, klass;
+{
+ return rb_funcall(super, rb_intern("inherited"), 1, klass);
+}
+
+VALUE
rb_define_class(name, super)
const char *name;
VALUE super;
@@ -179,6 +193,7 @@ rb_define_class(name, super)
return klass;
}
klass = rb_define_class_id(id, super);
+ rb_class_inherited(super, klass);
st_add_direct(rb_class_tbl, id, klass);
return klass;
@@ -205,8 +220,9 @@ rb_define_class_under(outer, name, super)
return klass;
}
klass = rb_define_class_id(id, super);
- rb_const_set(outer, id, klass);
rb_set_class_path(klass, outer, name);
+ rb_class_inherited(super, klass);
+ rb_const_set(outer, id, klass);
return klass;
}
@@ -653,9 +669,7 @@ rb_singleton_class(obj)
klass = RBASIC(obj)->klass;
}
else {
- klass = rb_singleton_class_new(RBASIC(obj)->klass);
- RBASIC(obj)->klass = klass;
- rb_singleton_class_attached(klass, obj);
+ klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
}
if (OBJ_TAINTED(obj)) {
OBJ_TAINT(klass);
diff --git a/eval.c b/eval.c
index 9f8f12a..d1a8e06 100644
--- a/eval.c
+++ b/eval.c
@@ -3214,8 +3214,9 @@ rb_eval(self, n)
override_class:
if (!super) super = rb_cObject;
klass = rb_define_class_id(node->nd_cname, super);
- rb_const_set(ruby_class, node->nd_cname, klass);
rb_set_class_path(klass,ruby_class,rb_id2name(node->nd_cname));
+ rb_class_inherited(super, klass);
+ rb_const_set(ruby_class, node->nd_cname, klass);
}
if (ruby_wrapper) {
rb_extend_object(klass, ruby_wrapper);
diff --git a/intern.h b/intern.h
index 16436a4..a83804f 100644
--- a/intern.h
+++ b/intern.h
@@ -88,6 +88,8 @@ VALUE rb_mod_dup _((VALUE));
VALUE rb_singleton_class_new _((VALUE));
VALUE rb_singleton_class_clone _((VALUE));
void rb_singleton_class_attached _((VALUE,VALUE));
+VALUE rb_make_metaclass _((VALUE, VALUE));
+VALUE rb_class_inherited _((VALUE, VALUE));
VALUE rb_define_class_id _((ID, VALUE));
VALUE rb_module_new _((void));
VALUE rb_define_module_id _((ID));
diff --git a/object.c b/object.c
index ea3eec7..87f241f 100644
--- a/object.c
+++ b/object.c
@@ -624,11 +624,9 @@ rb_class_s_new(argc, argv)
super = rb_cObject;
}
klass = rb_class_new(super);
- /* make metaclass */
- RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass);
- rb_singleton_class_attached(RBASIC(klass)->klass, klass);
+ rb_make_metaclass(klass, RBASIC(super)->klass);
rb_obj_call_init(klass, argc, argv);
- rb_funcall(super, rb_intern("inherited"), 1, klass);
+ rb_class_inherited(super, klass);
return klass;
}
@@ -1129,12 +1127,9 @@ Init_Object()
rb_cModule = boot_defclass("Module", rb_cObject);
rb_cClass = boot_defclass("Class", rb_cModule);
- metaclass = RBASIC(rb_cObject)->klass = rb_singleton_class_new(rb_cClass);
- rb_singleton_class_attached(metaclass, rb_cObject);
- metaclass = RBASIC(rb_cModule)->klass = rb_singleton_class_new(metaclass);
- rb_singleton_class_attached(metaclass, rb_cModule);
- metaclass = RBASIC(rb_cClass)->klass = rb_singleton_class_new(metaclass);
- rb_singleton_class_attached(metaclass, rb_cClass);
+ metaclass = rb_make_metaclass(rb_cObject, rb_cClass);
+ metaclass = rb_make_metaclass(rb_cModule, metaclass);
+ metaclass = rb_make_metaclass(rb_cClass, metaclass);
rb_mKernel = rb_define_module("Kernel");
rb_include_module(rb_cObject, rb_mKernel);
diff --git a/struct.c b/struct.c
index 21043cb..0b17eb0 100644
--- a/struct.c
+++ b/struct.c
@@ -156,6 +156,7 @@ make_struct(name, member, klass)
if (NIL_P(name)) {
nstr = rb_class_new(klass);
+ rb_class_inherited(klass, nstr);
}
else {
char *cname = StringValuePtr(name);