Skip to content

Reduce backref usage in split#6644

Merged
headius merged 2 commits intojruby:jruby-9.2from
headius:reduce_backref_in_split
Mar 31, 2021
Merged

Reduce backref usage in split#6644
headius merged 2 commits intojruby:jruby-9.2from
headius:reduce_backref_in_split

Conversation

@headius
Copy link
Member

@headius headius commented Mar 31, 2021

String#split appears to do nothing with the context backref slot
except using it to receive the MatchData from a regexp match and
eventually clearing it to nil. This patch sets up a thread-local
IRubyObject[] holder to use for that out value and avoids using
the context backref at all except for clearing it at the end.

This fixes #6640 by avoiding all reads of the context backref. It
may still cause problems for other backref-reading functions that
run concurrently and see the clearing to nil unexpectedly.

String#split appears to do nothing with the context backref slot
except using it to receive the MatchData from a regexp match and
eventually clearing it to nil. This patch sets up a thread-local
IRubyObject[] holder to use for that out value and avoids using
the context backref at all except for clearing it at the end.

This fixes jruby#6160 by avoiding all reads of the context backref. It
may still cause problems for other backref-reading functions that
run concurrently and see the clearing to nil unexpectedly.
@headius headius added this to the JRuby 9.2.18.0 milestone Mar 31, 2021
@headius
Copy link
Member Author

headius commented Mar 31, 2021

There are likely other methods that claim to read or write backref but actually only use it as an extra return value from Regexp functions.

See jruby#6640 for a failure that
occurred in JRuby due to using the context backref slot as an
"out" variable during regexp-based splitting.
@headius headius merged commit 6a0b3ba into jruby:jruby-9.2 Mar 31, 2021
@headius headius deleted the reduce_backref_in_split branch March 31, 2021 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.ClassCastException: org.jruby.RubyNil cannot be cast to org.jruby.RubyMatchData

1 participant