[MacRuby] #1179: OpenStruct overwrites regex globals - seriously breaks Rack/Sinatra
MacRuby
ruby-noreply at macosforge.org
Sat Mar 5 13:59:56 PST 2011
#1179: OpenStruct overwrites regex globals - seriously breaks Rack/Sinatra
---------------------------------+------------------------------------------
Reporter: scottg@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: blocker | Milestone:
Component: MacRuby | Keywords: openstruct rack sinatra control_tower
---------------------------------+------------------------------------------
Loving MacRuby, but found a serious bug: The MacRuby version of
OpenStruct#missing_method uses a regex, which blasts away any regex
globals in the caller's scope.
The problem is line 83 in #method_missing:
{{{
if mname =~ /=$/
}}}
Ruby MRI uses this instead:
{{{
if mname.chomp!('=')
}}}
It looks like you are trying to avoid chomping until you test whether it's
frozen, so you could do this:
{{{
if mname.end_with?('=')
}}}
----
This bug is absolutely a blocker.
Here's a small test case that shows how seriously this affects
Rack/Sinatra. Install the Sinatra gem and create the following Sinatra
app:
{{{
class Test < Sinatra::Base
get '/' { my_undefined_keyword }
end
}}}
Create a quick rackup file to launch this (leave show_errors enabled) and
run control_tower. Then try to load http://localhost:3000/. On my MacBook
Pro both processors get maxed out for 50 seconds while MacRuby tries to
build the error page!
This happens because Rack::ShowExceptions contains the following code
(#pretty, line 33):
{{{
frame = OpenStruct.new
if line =~ /(.*?):(\d+)(:in `(.*)')?/
frame.filename = $1
frame.lineno = $2.to_i
frame.function = $4
}}}
$2 and $4 get reset after the call to frame.filename so frame.lineno ends
up being '0'. Normally Sinatra shows a backtrace with +/- 7 lines of
context from your source files. But because of the line number error,
Sinatra ends up converting into HTML every line from every file that's
listed in the backtrace (as many times as their listed -- about 15,000
lines total). Which requires 180% utilization for 50 seconds.
That's just one example. This bug probably affect other libraries too.
--
Ticket URL: <http://www.macruby.org/trac/ticket/1179>
MacRuby <http://macruby.org/>
More information about the macruby-tickets
mailing list