summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-11 08:22:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-11 08:22:18 +0000
commitbe1d2c5f685d56e10239565e5eefba191de0e0be (patch)
treeca2c2a97c4a87726d0d70fed72954eea67110189 /class.c
parentda72e5a64442c9649689f347e2cc237ec3f41bf8 (diff)
* string.c (rb_str_slice_bang): if there's no corresponding
substring, slice! should return nil without exception. * array.c (rb_ary_insert): type fixed. * string.c (rb_str_split_m): accept separator value nil as well. * string.c (rb_str_become): was leaking memory. * class.c (rb_include_module): should not alter other classes/modules by inclusion. by this fix, local order may not be preserved for some cases. * class.c (include_class_new): module may be T_ICLASS; retrieve original module information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/class.c b/class.c
index 962a9ab..6fb7b51 100644
--- a/class.c
+++ b/class.c
@@ -318,6 +318,9 @@ include_class_new(module, super)
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_ICLASS);
+ if (BUILTIN_TYPE(module) == T_ICLASS) {
+ module = RBASIC(module)->klass;
+ }
if (!RCLASS(module)->iv_tbl) {
RCLASS(module)->iv_tbl = st_init_numtable();
}
@@ -363,19 +366,27 @@ rb_include_module(klass, 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");
/* ignore if the module included already in superclasses */
for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
- if (BUILTIN_TYPE(p) == T_ICLASS) {
+ switch (BUILTIN_TYPE(p)) {
+ case T_ICLASS:
if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) {
- c = p; /* move insertion point */
+ if (!superclass_seen) {
+ c = p; /* move insertion point */
+ }
goto skip;
}
+ break;
+ case T_CLASS:
+ superclass_seen = Qtrue;
+ break;
}
}
- RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
- c = RCLASS(c)->super;
+ c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
changed = 1;
skip:
module = RCLASS(module)->super;