Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

avoid cyclic module inclusions

  • Loading branch information...
commit b2a7f158b460c18ea4728054bea92024713e8378 1 parent 0678118
Laurent Sansonetti authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 eval.c
View
15 eval.c
@@ -543,6 +543,19 @@ rb_frame_callee(void)
* _mod_ or one of its ancestors. See also <code>Module#include</code>.
*/
+static void
+check_cyclic_include(VALUE klass, VALUE mod)
+{
+ VALUE m = mod;
+ do {
+ if (m == klass) {
+ rb_raise(rb_eArgError, "cyclic include detected");
+ }
+ m = RCLASS_SUPER(m);
+ }
+ while (RCLASS_SINGLETON(m));
+}
+
static VALUE
rb_mod_append_features(VALUE module, SEL sel, VALUE include)
{
@@ -555,6 +568,8 @@ rb_mod_append_features(VALUE module, SEL sel, VALUE include)
Check_Type(include, T_CLASS);
break;
}
+ check_cyclic_include(include, module);
+
if (RCLASS_RUBY(include)) {
VALUE sinclude = rb_make_singleton_class(RCLASS_SUPER(include));
RCLASS_SET_SUPER(include, sinclude);
Please sign in to comment.
Something went wrong with that request. Please try again.