JRuby

$~/Regexp.last_match lost when evaluation is inside a block

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1RC3
  • Fix Version/s: JRuby 1.1.2
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    2

Description

When a regex is evaluated inside a block, it seems like $~/Regexp.last_match doesn't survive completion of the block. Code snippet which raises an exception under failure attached.

This affects both jruby 1.1RC3 and trunk r6337.

Behavior compared against 1.8.6 r15749 and 1.9 r15811.

Note this is extracted from autotest and is a blocker for me using autotest.

  1. get_match_data_inside_block.diff
    25/Apr/08 1:09 PM
    0.7 kB
    Fabio Kung
  2. jruby_lm.rb
    25/Mar/08 12:15 PM
    0.2 kB
    Steven Parkes

Issue Links

Activity

Hide
Fabio Kung added a comment -

I've patched ZenTest to capture the matched data inside the block.
It's a quick fix until this issue gets resolved.

Show
Fabio Kung added a comment - I've patched ZenTest to capture the matched data inside the block. It's a quick fix until this issue gets resolved.
Hide
Charles Oliver Nutter added a comment -

I can fix this by not doing a copy of the block's host frame, but that would break other things. I'm going to poke around MRI a bit to see where backrefs are actually supposed to be located.

Show
Charles Oliver Nutter added a comment - I can fix this by not doing a copy of the block's host frame, but that would break other things. I'm going to poke around MRI a bit to see where backrefs are actually supposed to be located.
Hide
Charles Oliver Nutter added a comment -

This snippit, and a quick examination of the code, leads me to believe Ruby stores $~ and $_ in the topmost enclosing scope:

~/NetBeansProjects/jruby ➔ ruby -e "def foo; yield; end; 'foo' =~ /(foo)/; foo { 'bar' =~ /(bar)/ }; p \$~[0]"
"bar"

We need more specs for $~ and $_ for sure though, and we need to find a way around the frame copying.

Show
Charles Oliver Nutter added a comment - This snippit, and a quick examination of the code, leads me to believe Ruby stores $~ and $_ in the topmost enclosing scope:
~/NetBeansProjects/jruby ➔ ruby -e "def foo; yield; end; 'foo' =~ /(foo)/; foo { 'bar' =~ /(bar)/ }; p \$~[0]"
"bar"
We need more specs for $~ and $_ for sure though, and we need to find a way around the frame copying.
Hide
Charles Oliver Nutter added a comment -

Pretty sure now this is a side effect of the proc that's involved; since we clone the frame the proc is associated with (to keep it safe across threads, avoid it wiping out threads that are being used for other things). So if we can fix the cloning of frames in procs, we will probably have this.

I added some specs for $~ and $_.

Show
Charles Oliver Nutter added a comment - Pretty sure now this is a side effect of the proc that's involved; since we clone the frame the proc is associated with (to keep it safe across threads, avoid it wiping out threads that are being used for other things). So if we can fix the cloning of frames in procs, we will probably have this. I added some specs for $~ and $_.
Hide
Marcin Mielzynski added a comment -

Revision 6654 still fails.

Show
Marcin Mielzynski added a comment - Revision 6654 still fails.
Hide
Charles Oliver Nutter added a comment -

Fixed by framing changes in r6696, with a test added in r6698.

Show
Charles Oliver Nutter added a comment - Fixed by framing changes in r6696, with a test added in r6698.
Hide
Fabio Kung added a comment -

great Charles! I can confirm that ZenTest/autotest is working out-of-the-box.

Show
Fabio Kung added a comment - great Charles! I can confirm that ZenTest/autotest is working out-of-the-box.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: