summaryrefslogtreecommitdiffstats
path: root/class.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-07 08:56:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-11-07 08:56:18 +0000
commit1f5ecc52506ac5db7191756843046d77436e8e64 (patch)
tree6fc07fb23fb397b3ce755307112d8253d0c1fc52 /class.c
parent40a4d1c6e002fca5325e5fb231262754e75aa6d0 (diff)
downloadruby-1f5ecc52506ac5db7191756843046d77436e8e64.tar.gz
ruby-1f5ecc52506ac5db7191756843046d77436e8e64.tar.xz
ruby-1f5ecc52506ac5db7191756843046d77436e8e64.zip
* class.c (rb_include_module): revert duplicate inclusion of
modules. [ruby-dev:29793] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/class.c b/class.c
index c204fdd41..c7fc1df37 100644
--- a/class.c
+++ b/class.c
@@ -344,7 +344,7 @@ include_class_new(VALUE module, VALUE super)
void
rb_include_module(VALUE klass, VALUE module)
{
- VALUE c;
+ VALUE p, c;
int changed = 0;
rb_frozen_class_p(klass);
@@ -359,11 +359,29 @@ rb_include_module(VALUE klass, VALUE module)
OBJ_INFECT(klass, module);
c = klass;
while (module) {
+ int superclass_seen = Qfalse;
+
if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
rb_raise(rb_eArgError, "cyclic include detected");
- RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
- c = RCLASS(c)->super;
+ /* ignore if the module included already in superclasses */
+ for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
+ switch (BUILTIN_TYPE(p)) {
+ case T_ICLASS:
+ if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) {
+ if (!superclass_seen) {
+ c = p; /* move insertion point */
+ }
+ goto skip;
+ }
+ break;
+ case T_CLASS:
+ superclass_seen = Qtrue;
+ break;
+ }
+ }
+ c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
changed = 1;
+ skip:
module = RCLASS(module)->super;
}
if (changed) rb_clear_cache();