Skip to content

compile.c: Handle anonymous variables in outer_variable_cmp #13436

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

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

byroot
Copy link
Member

@byroot byroot commented May 24, 2025

[Bug #21370]

No idea if this is the correct way to fix it. I assume it is indeed meant to be anonymous, but perhaps it shouldn't?

@byroot byroot requested review from ko1 and k0kubun May 24, 2025 08:04
@tenderlove
Copy link
Member

I think your patch seems alright. I was going to suggest the following:

diff --git a/compile.c b/compile.c
index 7eb953203c..9bfff6961f 100644
--- a/compile.c
+++ b/compile.c
@@ -13366,6 +13366,9 @@ static enum rb_id_table_iterator_result
 store_outer_variable(ID id, VALUE val, void *dump)
 {
     struct outer_variable_list *ovlist = dump;
+    if (id & ID_INTERNAL) {
+        return ID_TABLE_CONTINUE;
+    }
     struct outer_variable_pair *pair = &ovlist->pairs[ovlist->num++];
     pair->id = id;
     pair->name = rb_id2str(id);
@@ -13399,7 +13402,7 @@ ibf_dump_outer_variables(struct ibf_dump *dump, const rb_iseq_t *iseq)
         struct outer_variable_list *ovlist = RB_ALLOCV(buff, buffsize);
         ovlist->num = 0;
         rb_id_table_foreach(ovs, store_outer_variable, ovlist);
-        ruby_qsort(ovlist->pairs, size, sizeof(struct outer_variable_pair), outer_variable_cmp, NULL);
+        ruby_qsort(ovlist->pairs, ovlist->num, sizeof(struct outer_variable_pair), outer_variable_cmp, NULL);
         for (size_t i = 0; i < size; ++i) {
             ID id = ovlist->pairs[i].id;
             ID val = ovlist->pairs[i].val;

But then maybe the iseqs wouldn't round-trip correctly.

I assume we're sorting these ids by name because when you load the iseq in a different process the id will change and the "name" is the only real stable key we have. I'm not sure what impact that has on anonymous locals though.

@byroot
Copy link
Member Author

byroot commented May 26, 2025

But then maybe the iseqs wouldn't round-trip correctly.

Very good point. Rather than assert I fixed the crash, I should assert the code is still functional once roundtriped.

I'll dig a bit, surely that isn't the only internal id in ISeq that need to be roundtriped.

@byroot
Copy link
Member Author

byroot commented Jun 2, 2025

I should assert the code is still functional once roundtriped.

I did this today with @etiennebarrie, seem to work fine.

@byroot byroot enabled auto-merge (rebase) June 2, 2025 11:33
@byroot byroot merged commit ff222ac into ruby:master Jun 2, 2025
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy