summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-10 14:59:12 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-10 14:59:12 +0000
commitc1183af5753eba52f5c8a0057cdec8673a5a18db (patch)
tree79772c829083eb4efdce71da23587334586118c2 /class.c
parent80a01400db7875c7192ec67a025fe3ba559cc4b0 (diff)
reverted Module#mix -- r31873, r31917 and r31918.
-- * class.c (rb_mix_module): implement Module#mix. -- * class.c (check_mix_method_i, do_mix_method_i): not mix methods -- * test/ruby/test_module.rb (TestModule#test_mix_const): test for git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c173
1 files changed, 26 insertions, 147 deletions
diff --git a/class.c b/class.c
index d427393081..df19812d15 100644
--- a/class.c
+++ b/class.c
@@ -120,26 +120,27 @@ rb_class_new(VALUE super)
return rb_class_boot(super);
}
-static void
-rb_mod_clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
+struct clone_method_data {
+ st_table *tbl;
+ VALUE klass;
+};
+
+VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);
+
+static int
+clone_method(ID mid, const rb_method_entry_t *me, struct clone_method_data *data)
{
VALUE newiseqval;
if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
rb_iseq_t *iseq;
- newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
+ newiseqval = rb_iseq_clone(me->def->body.iseq->self, data->klass);
GetISeqPtr(newiseqval, iseq);
- rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
+ rb_add_method(data->klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
RB_GC_GUARD(newiseqval);
}
else {
- rb_method_entry_set(klass, mid, me, me->flag);
+ rb_method_entry_set(data->klass, mid, me, me->flag);
}
-}
-
-static int
-clone_method_i(st_data_t key, st_data_t value, st_data_t data)
-{
- rb_mod_clone_method((VALUE)data, (ID)key, (const rb_method_entry_t *)value);
return ST_CONTINUE;
}
@@ -188,11 +189,15 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
}
if (RCLASS_M_TBL(orig)) {
+ struct clone_method_data data;
+
if (RCLASS_M_TBL(clone)) {
rb_free_m_table(RCLASS_M_TBL(clone));
}
- RCLASS_M_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
+ data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
+ data.klass = clone;
+ st_foreach(RCLASS_M_TBL(orig), clone_method,
+ (st_data_t)&data);
}
return clone;
@@ -222,11 +227,12 @@ rb_singleton_class_clone(VALUE obj)
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
+ struct clone_method_data data;
/* copy singleton(unnamed) class */
VALUE clone = class_alloc((RBASIC(klass)->flags & ~(FL_MARK)), 0);
if (BUILTIN_TYPE(obj) == T_CLASS) {
- RBASIC(clone)->klass = clone;
+ RBASIC(clone)->klass = (VALUE)clone;
}
else {
RBASIC(clone)->klass = rb_singleton_class_clone(klass);
@@ -241,10 +247,13 @@ rb_singleton_class_clone(VALUE obj)
st_foreach(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
}
RCLASS_M_TBL(clone) = st_init_numtable();
- st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone);
- rb_singleton_class_attached(RBASIC(clone)->klass, clone);
+ data.tbl = RCLASS_M_TBL(clone);
+ data.klass = (VALUE)clone;
+ st_foreach(RCLASS_M_TBL(klass), clone_method,
+ (st_data_t)&data);
+ rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
- return clone;
+ return (VALUE)clone;
}
}
@@ -695,136 +704,6 @@ rb_include_module(VALUE klass, VALUE module)
if (changed) rb_clear_cache();
}
-struct mixing_arg {
- st_table *mtbl;
- ID id;
- st_table *aliasing;
- VALUE klass;
-};
-
-static int
-check_mix_const_i(st_data_t key, st_data_t value, st_data_t arg)
-{
- struct mixing_arg *argp = (struct mixing_arg *)arg;
- ID id = (ID)key;
- st_table *aliasing = argp->aliasing;
- st_data_t alias;
-
- if (!rb_is_const_id(id)) return ST_CONTINUE;
- if (aliasing && st_lookup(aliasing, ID2SYM(id), &alias)) {
- id = rb_to_id(alias);
- }
- if (st_lookup(argp->mtbl, id, NULL)) {
- argp->id = id;
- return ST_STOP;
- }
- return ST_CONTINUE;
-}
-
-static int
-do_mix_const_i(st_data_t key, st_data_t value, st_data_t arg)
-{
- struct mixing_arg *argp = (struct mixing_arg *)arg;
- ID id = (ID)key;
- st_table *aliasing = argp->aliasing;
- st_data_t old, alias;
-
- if (!rb_is_const_id(id)) return ST_CONTINUE;
- if (aliasing && st_lookup(aliasing, ID2SYM(id), &alias)) {
- id = rb_to_id(alias);
- }
- if (st_lookup(argp->mtbl, id, &old)) {
- argp->id = id;
- return ST_STOP;
- }
- st_insert(argp->mtbl, id, value);
- return ST_CONTINUE;
-}
-
-static int
-check_mix_method_i(st_data_t key, st_data_t value, st_data_t arg)
-{
- struct mixing_arg *argp = (struct mixing_arg *)arg;
- ID id = (ID)key;
- st_table *aliasing = argp->aliasing;
- st_data_t alias;
-
- if (aliasing && st_lookup(aliasing, ID2SYM(id), &alias)) {
- if (NIL_P(alias)) return ST_CONTINUE;
- id = rb_to_id(alias);
- }
- if (st_lookup(argp->mtbl, id, NULL)) {
- argp->id = id;
- return ST_STOP;
- }
- return ST_CONTINUE;
-}
-
-static int
-do_mix_method_i(st_data_t key, st_data_t value, st_data_t arg)
-{
- struct mixing_arg *argp = (struct mixing_arg *)arg;
- ID id = (ID)key;
- st_table *aliasing = argp->aliasing;
- st_data_t old, alias;
-
- if (aliasing && st_lookup(aliasing, ID2SYM(id), &alias)) {
- if (NIL_P(alias)) return ST_CONTINUE;
- id = rb_to_id(alias);
- }
- if (st_lookup(argp->mtbl, id, &old)) {
- argp->id = id;
- return ST_STOP;
- }
- rb_mod_clone_method(argp->klass, id, (rb_method_entry_t *)value);
- return ST_CONTINUE;
-}
-
-void
-rb_mix_module(VALUE klass, VALUE module, st_table *constants, st_table *methods)
-{
- st_table *mtbl_from;
- struct mixing_arg methodarg, constarg;
-
- rb_frozen_class_p(klass);
- if (!OBJ_UNTRUSTED(klass)) {
- rb_secure(4);
- }
-
- if (TYPE(module) != T_MODULE) {
- Check_Type(module, T_MODULE);
- }
-
- OBJ_INFECT(klass, module);
-
- mtbl_from = RMODULE_M_TBL(module);
- methodarg.mtbl = RMODULE_M_TBL(klass);
- methodarg.id = 0;
- methodarg.aliasing = methods;
- methodarg.klass = klass;
- constarg.mtbl = RMODULE_IV_TBL(klass);
- constarg.id = 0;
- constarg.aliasing = constants;
-
- st_foreach(mtbl_from, check_mix_method_i, (st_data_t)&methodarg);
- if (methodarg.id) {
- rb_raise(rb_eArgError, "method would conflict - %s", rb_id2name(methodarg.id));
- }
- st_foreach(mtbl_from, check_mix_const_i, (st_data_t)&constarg);
- if (constarg.id) {
- rb_raise(rb_eArgError, "constant would conflict - %s", rb_id2name(constarg.id));
- }
- st_foreach(mtbl_from, do_mix_method_i, (st_data_t)&methodarg);
- if (methodarg.id) {
- rb_raise(rb_eArgError, "method would conflict - %s", rb_id2name(methodarg.id));
- }
- st_foreach(mtbl_from, do_mix_const_i, (st_data_t)&constarg);
- if (constarg.id) {
- rb_raise(rb_eArgError, "constant would conflict - %s", rb_id2name(constarg.id));
- }
- rb_vm_inc_const_missing_count();
-}
-
/*
* call-seq:
* mod.included_modules -> array