92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'ext/include_complete/include_complete_one.c', line 92
static VALUE
rb_include_complete_module_one(VALUE klass, VALUE module)
{
VALUE p, c;
int changed = 0;
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);
c = klass;
/* ensure singleton classes exist, both for includer and includee */
rb_singleton_class(module);
rb_singleton_class(klass);
while (module) {
int superclass_seen = FALSE;
if (RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
rb_raise(rb_eArgError, "cyclic include detected");
/* ignore if the module included already in superclasses */
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
switch (BUILTIN_TYPE(p)) {
case T_ICLASS:
if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
if (!superclass_seen) {
c = p; /* move insertion point */
}
goto skip;
}
break;
case T_CLASS:
superclass_seen = TRUE;
break;
}
}
/* we're including the module, so create the iclass */
VALUE imod = include_class_new(module, RCLASS_SUPER(c));
/* module gets included directly above c, so set the super */
RCLASS_SUPER(c) = imod;
/* also do the same for parallel inheritance chain (singleton classes) */
RCLASS_SUPER(KLASS_OF(c)) = KLASS_OF(imod);
c = imod;
if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
changed = 1;
skip:
module = RCLASS_SUPER(module);
}
if (changed) rb_clear_cache();
return Qnil;
}
|