summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-06 21:50:06 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-06 21:50:06 +0000
commitb51416e21f7c0df7d29a7ccd7660f794b6055620 (patch)
treec40497dc8c419b596aa0c5679e1d8621cb474562 /object.c
parent1e51675654ec0a5624d78786e23851df73e14030 (diff)
* eval.c (rb_call0): update ruby_class as well as ruby_cref.
(ruby-bugs-ja PR#540) * eval.c (rb_yield_0): remove ruby_frame->cbase and unify to ruby_cref. [ruby-talk:78141] * eval.c: initialize /* OK */ variables by Qnil to stop warnings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/object.c b/object.c
index 712c8b7581..67528fb925 100644
--- a/object.c
+++ b/object.c
@@ -675,49 +675,52 @@ rb_mod_cmp(mod, arg)
return INT2FIX(1);
}
+static VALUE rb_module_s_alloc _((VALUE));
static VALUE
-rb_mod_initialize(module)
- VALUE module;
+rb_module_s_alloc(klass)
+ VALUE klass;
{
- if (rb_block_given_p()) {
- rb_mod_module_eval(0, 0, module);
- }
- return Qnil;
+ VALUE mod = rb_module_new();
+
+ RBASIC(mod)->klass = klass;
+ return mod;
}
static VALUE
-rb_class_initialize(argc, argv, klass)
+rb_class_s_alloc(argc, argv)
int argc;
VALUE *argv;
- VALUE klass;
{
- return rb_mod_initialize(klass);
+ return rb_class_boot(0);
}
-static VALUE rb_module_s_alloc _((VALUE));
static VALUE
-rb_module_s_alloc(klass)
- VALUE klass;
+rb_mod_initialize(module)
+ VALUE module;
{
- VALUE mod = rb_module_new();
-
- RBASIC(mod)->klass = klass;
- return mod;
+ if (rb_block_given_p()) {
+ rb_mod_module_eval(0, 0, module);
+ }
+ return Qnil;
}
static VALUE
-rb_class_s_new(argc, argv)
+rb_class_initialize(argc, argv, klass)
int argc;
VALUE *argv;
+ VALUE klass;
{
- VALUE super, klass;
+ VALUE super;
+ if (RCLASS(klass)->super != 0) {
+ rb_raise(rb_eTypeError, "already initialized class");
+ }
if (rb_scan_args(argc, argv, "01", &super) == 0) {
super = rb_cObject;
}
- klass = rb_class_new(super);
+ RCLASS(klass)->super = super;
rb_make_metaclass(klass, RBASIC(super)->klass);
- rb_obj_call_init(klass, argc, argv);
+ rb_mod_initialize(klass);
rb_class_inherited(super, klass);
return klass;
@@ -729,6 +732,9 @@ rb_obj_alloc(klass)
{
VALUE obj;
+ if (RCLASS(klass)->super == 0) {
+ rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
+ }
if (FL_TEST(klass, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "can't create instance of virtual class");
}
@@ -769,6 +775,9 @@ rb_class_superclass(klass)
{
VALUE super = RCLASS(klass)->super;
+ if (!super) {
+ rb_raise(rb_eTypeError, "uninitialized class");
+ }
while (TYPE(super) == T_ICLASS) {
super = RCLASS(super)->super;
}
@@ -1491,8 +1500,7 @@ Init_Object()
rb_define_method(rb_cModule, "<=", rb_mod_le, 1);
rb_define_method(rb_cModule, ">", rb_mod_gt, 1);
rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
- rb_define_method(rb_cModule, "clone", rb_mod_clone, 0);
- rb_define_method(rb_cModule, "dup", rb_mod_dup, 0);
+ rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1);
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0);
rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1);
@@ -1524,8 +1532,7 @@ Init_Object()
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
- rb_undef_alloc_func(rb_cClass);
- rb_define_singleton_method(rb_cClass, "new", rb_class_s_new, -1);
+ rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
rb_undef_method(rb_cClass, "extend_object");
rb_undef_method(rb_cClass, "append_features");