[ruby-core:117712] [Ruby master Bug#20455] rb_errinfo() inconsistent with $! in the caller Ruby code
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2024-04-25 19:37:04 UTC
List:
ruby-core #117712
Issue #20455 has been updated by Eregon (Benoit Daloze).
@ko1 (and the code) pointed me to `$!` is `rb_ec_get_errinfo`, which walks the stack to find the first `rescue`/`ensure` (does it stop at the first ensure if it's an ensure without an active exception?) and uses `ec->errinfo` if not,
while `rb_errinfo` is just `GET_EC()->errinfo`.
I'm not sure what this means in terms of semantics, that they are the same but only if no rescue/ensure on the stack, and otherwise they are fully separate?
It sounds like very odd semantics.
BTW the header docs at https://github.com/ruby/ruby/blob/6f4f360fc46269eaba753cafe557519677a45a11/include/ruby/internal/error.h#L77-L84 seems not quite true and rather misleading.
----------------------------------------
Bug #20455: rb_errinfo() inconsistent with $! in the caller Ruby code
https://bugs.ruby-lang.org/issues/20455#change-108121
* Author: Eregon (Benoit Daloze)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-04-25T08:12:47Z master 64bd8e41df) [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This (slightly modified for clarity) test in ruby/spec demonstrates the unexpected result:
```ruby
describe "rb_errinfo" do
def err
$!
end
it "is cleared when entering a C method" do
begin
raise StandardError
rescue
$!.class.should == StandardError
err.class.should == StandardError
@s.rb_errinfo().should == nil
end
end
```
Why does `rb_errinfo()` return nil there, when $! is set in the caller (and $! isn't per frame but per thread, as shown with `err`)?
Is this bug?
If not, what is the logic and reason for clearing `$!` when calling a method defined in C?
--
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/