Project

General

Profile

Bug #7308

Infinite recursion on circular 'using'

Added by charliesome (Charlie Somerville) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
2.0.0-preview1
[ruby-core:49092]

Description

This code causes infinite recursion:

module X; using X; end

Note that any circular 'using' will cause infinite recursion, not just a module using itself:

module A; end
module B; using A; end
module A; using B; end

This raises a SystemStackError on my OS X Lion machine, but it causes a segmentation fault on Ubuntu 10.04 i686 (running 2.6.32-38). I've attached a dump of an IRB session which finishes with a segfault.

irb-session.txt (42.2 KB) irb-session.txt charliesome (Charlie Somerville), 11/08/2012 07:15 PM
prevent-circular-using.patch (1.7 KB) prevent-circular-using.patch charliesome (Charlie Somerville), 11/09/2012 07:37 PM

Associated revisions

Revision 37646
Added by shugo (Shugo Maeda) over 4 years ago

* eval.c (rb_mod_using): raise an ArgumentError if cyclic using is
detected. based on the patch by Charlie Somerville.
Bug #7308

* test/ruby/test_refinement.rb: related test.

Revision 37646
Added by shugo (Shugo Maeda) over 4 years ago

* eval.c (rb_mod_using): raise an ArgumentError if cyclic using is
detected. based on the patch by Charlie Somerville.
Bug #7308

* test/ruby/test_refinement.rb: related test.

Revision 37646
Added by shugo (Shugo Maeda) over 4 years ago

* eval.c (rb_mod_using): raise an ArgumentError if cyclic using is
detected. based on the patch by Charlie Somerville.
Bug #7308

* test/ruby/test_refinement.rb: related test.

Revision 37646
Added by shugo (Shugo Maeda) over 4 years ago

* eval.c (rb_mod_using): raise an ArgumentError if cyclic using is
detected. based on the patch by Charlie Somerville.
Bug #7308

* test/ruby/test_refinement.rb: related test.

History

#1 [ruby-core:49100] Updated by mame (Yusuke Endoh) over 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to shugo (Shugo Maeda)
  • Target version set to 2.0.0

#2 [ruby-core:49158] Updated by charliesome (Charlie Somerville) over 4 years ago

I've attached a patch that does a simple DFS to make sure no circular using relationship is created.

#3 Updated by shugo (Shugo Maeda) over 4 years ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

This issue was solved with changeset r37646.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • eval.c (rb_mod_using): raise an ArgumentError if cyclic using is
    detected. based on the patch by Charlie Somerville.
    Bug #7308

  • test/ruby/test_refinement.rb: related test.

#4 [ruby-core:49288] Updated by shugo (Shugo Maeda) over 4 years ago

charliesome (Charlie Somerville) wrote:

I've attached a patch that does a simple DFS to make sure no circular using relationship is created.

Thank you. I've changed it to raise an ArgumentError instead of TypeError for the consistency with the cyclic include detection.

Also available in: Atom PDF