-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Allow caller/caller_locations to take a block #5031
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
Conversation
If caller/caller_locations is passed a block, the block is yielded the string or Thread::Backtrace::Location object as the VM frames are being scanned. The caller can break/return for an early exit. This allows for constructing partial backtraces where you don't know the size or level of the backtrace up front, as the part of the backtrace you want depends on the location. This has rb_ec_partial_backtrace_object accept to_str and do_yield arguments. If do_yield is true, then the array of backtrace strings/locations is created up front, and for each frame of the backtrace, after the string/location is added to the array, it is yielded to the block. If the array is created up front, we skip recreating it after the scan. Implements [Feature #16663]
I believe @jeremyevans' code but for the spec it should get Matz's approval. |
Correct. I added this to the next dev meeting earlier today. |
Does it mean all entries are created upfront? If so I think that defeats the point of this feature, which should only walk the necessary frames (which is also what can make it tricky to implement). |
No. This yields to the block as each entry is created, it does not create all entries up front. The comment states that if an array was created up front (only done if a block is passed), then we don't create a new array for the backtrace if we get to the end of the array, we just use the already created array. |
Ah I see, thanks for the clarification. |
Now |
Sure. |
I missed the ping for this until now. Unfortunate that it was rejected. Consumers of |
I replied to the ruby-lang issue here: https://bugs.ruby-lang.org/issues/16663#change-95288 |
@headius The particular approach in this pull request was rejected, however, matz is still open to the feature. Once we get consensus on how the feature should work, I'll submit another PR to implement it. |
If caller/caller_locations is passed a block, the block is yielded
the string or Thread::Backtrace::Location object as the VM frames
are being scanned. The caller can break/return for an early exit.
This allows for constructing partial backtraces where you don't
know the size or level of the backtrace up front, as the part
of the backtrace you want depends on the location.
This has rb_ec_partial_backtrace_object accept to_str and do_yield
arguments. If do_yield is true, then the array of backtrace
strings/locations is created up front, and for each frame of the
backtrace, after the string/location is added to the array, it is
yielded to the block. If the array is created up front, we skip
recreating it after the scan.
Implements [Feature #16663]
Documentation/NEWS not modified yet, I will take care of that
before merging if this is accepted.