-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More comprehensive recursion guard. #460
Changes from 3 commits
9ebceb8
09c043b
a2212c9
7baabb3
2ad4cf2
a8bfa13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Thread | ||
def recursion_guard_outer(identifier, obj, &block) | ||
# We want to throw something less likely to be caught accidentally outside | ||
# our own code than the recursion identifier. Ideally this should be an | ||
# object that is unique to this particular recursion guard. Since doing | ||
# that properly requires pushing extra state all the way up into | ||
# ExecutionContext, we do this instead. | ||
throw_symbol = "__recursion_guard_#{identifier}".to_sym | ||
|
||
if self.in_recursion_guard?(identifier) | ||
self.recursion_guard(identifier, obj) do |recursion| | ||
if !recursion | ||
yield(false) | ||
else | ||
throw(throw_symbol) | ||
end | ||
end | ||
else | ||
self.recursion_guard(identifier, obj) do |recursion| | ||
catch(throw_symbol) do | ||
return yield(false) | ||
end | ||
return yield(true) | ||
end | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't used yet, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, but I need it for Array#hash in #456. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is becoming my official theme song, but let's split this up :D, so this just has the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, just what's needed. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have been more precise, just what's needed for the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class TestExecutionContext(object): | ||
def test_recursion_guard(self, space): | ||
f = "my_func" | ||
x = object() | ||
y = object() | ||
with space.getexecutioncontext().recursion_guard(x) as in_recursion: | ||
with space.getexecutioncontext().recursion_guard(f, x) as in_recursion: | ||
assert not in_recursion | ||
with space.getexecutioncontext().recursion_guard(y) as ir2: | ||
with space.getexecutioncontext().recursion_guard(f, y) as ir2: | ||
assert not ir2 | ||
with space.getexecutioncontext().recursion_guard(x) as ir3: | ||
with space.getexecutioncontext().recursion_guard(f, x) as ir3: | ||
assert ir3 | ||
with space.getexecutioncontext().recursion_guard(x) as ir3: | ||
with space.getexecutioncontext().recursion_guard(f, x) as ir3: | ||
assert ir3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change in API from returning the the
in_recursion
value to yielding it to the block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into a case where not letting the block decide what to do when recursion is detected made things difficult, but I'm not sure if that's an issue anymore.