[#113435] [Ruby master Feature#19634] Pattern matching dynamic key — "baweaver (Brandon Weaver) via ruby-core" <ruby-core@...>
Issue #19634 has been reported by baweaver (Brandon Weaver).
6 messages
2023/05/09
[#113489] [Ruby master Bug#19642] Remove vectored read/write from `io.c`. — "ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>
Issue #19642 has been reported by ioquatix (Samuel Williams).
10 messages
2023/05/15
[ruby-core:113501] [Ruby master Bug#18743] Enumerator#next / peek re-use each others stacktraces
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-05-17 02:03:48 UTC
List:
ruby-core #113501
Issue #18743 has been updated by nobu (Nobuyoshi Nakada).
Seems find to me.
One thing I concerned, `stop_exc` will be re-created every times, and no wa=
y to know where it was first used up.
How about chaining by `cause`?
```diff
diff --git a/enumerator.c b/enumerator.c
index b33c1713718..1cc8f9108cf 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -30,6 +30,9 @@
#include "internal/rational.h"
#include "ruby/ruby.h"
=20
+extern ID ruby_static_id_cause;
+#define id_cause ruby_static_id_cause
+
/*
* Document-class: Enumerator
*
@@ -787,8 +790,16 @@ get_next_values(VALUE obj, struct enumerator *e)
{
VALUE curr, vs;
=20
- if (e->stop_exc)
- rb_exc_raise(e->stop_exc);
+ if (e->stop_exc) {
+ VALUE exc =3D e->stop_exc;
+ VALUE result =3D rb_attr_get(exc, id_result);
+ VALUE mesg =3D rb_attr_get(exc, idMesg);
+ if (!NIL_P(mesg)) mesg =3D rb_str_dup(mesg);
+ VALUE stop_exc =3D rb_exc_new_str(rb_eStopIteration, mesg);
+ rb_ivar_set(stop_exc, id_result, result);
+ rb_ivar_set(stop_exc, id_cause, exc);
+ rb_exc_raise(stop_exc);
+ }
=20
curr =3D rb_fiber_current();
=20
```
In the test, save `$!` at the first `rescue` then `assert_same(cause, exc.c=
ause)`.
----------------------------------------
Bug #18743: Enumerator#next / peek re-use each others stacktraces
https://bugs.ruby-lang.org/issues/18743#change-103096
* Author: sos4nt (Stefan Sch=FC=DFler)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I encountered an odd behavior.
If I rescue the `StopIteration` exception from `peek` and call `next` after=
wards: (or vice-versa)
```ruby
# enum.rb # 1
# 2
enum =3D [].each # 3
enum.peek rescue nil # 4
enum.next # 5
```
it will show the stacktrace from the rescued `peek` call:
```
$ ruby enum.rb
enum.rb:4:in `peek': iteration reached an end (StopIteration)
from enum.rb:4:in `<main>'
```
Whereas the error should refer to `next` on line number 5.
The same happens when calling `peek` after `next` or when having muliple `p=
eek` / `next` calls:
```ruby
# enum.rb # 1
# 2
enum =3D [].each # 3
enum.peek rescue nil # 4
enum.next rescue nil # 5
enum.peek rescue nil # 6
puts "line #{__LINE__}" # 7
enum.next # 8
```
The stacktrace from the first (rescued) `peek` or `next` call will be shown=
which doesn't reflect the actual error location:
```
$ ruby enum.rb
line 7
enum.rb:4:in `peek': iteration reached an end (StopIteration)
from enum.rb:4:in `<main>'
```
This is very confusing when debugging code.
---Files--------------------------------
01-Recreate-stacktrace-enumerator.patch (1.29 KB)
--=20
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-c=
ore.ml.ruby-lang.org/