[ruby-core:105629] [Ruby master Bug#18250] Anonymous variables seem to break `Ractor.make_shareable`
From:
"nobu (Nobuyoshi Nakada)" <noreply@...>
Date:
2021-10-13 07:46:54 UTC
List:
ruby-core #105629
Issue #18250 has been updated by nobu (Nobuyoshi Nakada).
```diff
commit 147cbbc4a648bf9671efec2604a00305ef74f2a6
Author: Nobuyoshi Nakada <nobu@ruby-lang.org>
AuthorDate: 2021-10-13 14:25:34 +0900
Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
CommitDate: 2021-10-13 16:46:16 +0900
rb_id_serial_to_id: return unnamed ID as an internal ID
diff --git a/symbol.c b/symbol.c
index 94a751d5e3d..00044fd3902 100644
--- a/symbol.c
+++ b/symbol.c
@@ -486,7 +486,8 @@ rb_id_serial_to_id(rb_id_serial_t num)
{
if (is_notop_id((ID)num)) {
VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM);
- return SYM2ID(sym);
+ if (sym) return SYM2ID(sym);
+ return ((ID)num << ID_SCOPE_SHIFT) | ID_INTERNAL | ID_STATIC_SYM;
}
else {
return (ID)num;
```
----------------------------------------
Bug #18250: Anonymous variables seem to break `Ractor.make_shareable`
https://bugs.ruby-lang.org/issues/18250#change-94119
* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin20]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
The following code breaks with a strange error:
```ruby
def foo(*); ->{ super };end
Ractor.make_shareable(foo) # expected Symbol
```
Output:
```
[aaron@tc ~/g/ruby (master)]$ cat test.rb
def foo(*); ->{ super };end
Ractor.make_shareable(foo) # expected Symbol
[aaron@tc ~/g/ruby (master)]$ ruby test.rb
<internal:ractor>:816:in `make_shareable': wrong argument type false (expected Symbol) (TypeError)
from test.rb:2:in `<main>'
[aaron@tc ~/g/ruby (master)]$
```
The reason is because the `*` parameter has no name, but Ractor tries to find the name so it can make an exception.
I *expect* the above program to raise an `Ractor::IsolationError`, but instead it raises a `TypeError`.
I've attached a patch that fixes this bug.
---Files--------------------------------
0001-Give-params-a-name.patch (3.33 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>