[#115884] Windows Ruby 3.2.2: Non-English character added to Windows Registry String Value — Jay Mav via ruby-core <ruby-core@...>
Hello,
3 messages
2023/12/24
[ruby-core:115701] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations
From:
"zverok (Victor Shepelev) via ruby-core" <ruby-core@...>
Date:
2023-12-11 21:18:30 UTC
List:
ruby-core #115701
Issue #20059 has been reported by zverok (Victor Shepelev).
----------------------------------------
Bug #20059: TracePoint#enable can be called multiple times, increasing the number of invokations
https://bugs.ruby-lang.org/issues/20059
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I just stumbled upon this accidentally (created a tracepoint with `TracePoint.trace`, and then `enable`d it).
My initial example
```ruby
trace = TracePoint.trace(:raise) do |tp|
puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
trace.enable # shouldn't do this, it was already enabled!
raise "foo"
```
This prints
```
Exception raised: #<RuntimeError: foo> at test.rb:5
Exception raised: #<RuntimeError: foo> at test.rb:5
```
Twice.
If I'll remove the "unnecessary" `trace.enable`, it prints it once.
So the theory is "multiple enables = multiple invokations of a tracepoint"...
```ruby
trace = TracePoint.trace(:raise) do |tp|
puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
5.times { trace.enable }
raise "foo"
```
...and indeed, this code prints the "Exception raised:" message 6 times.
I don't see anything about this behavior in the [method's docs](https://docs.ruby-lang.org/en/master/TracePoint.html#method-i-enable) or class docs, and can't think of a plausible explanation. But it was this way since Ruby 2.0, and either it _should_ be this way, or it bothers nobody :)
I wonder:
* is there a reasonable explanation for this?
* if so, shouldn't it be documented somewhere?..
Or is it some part of a pattern of how the `TracePoint` works that I am missing here?..
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/