Skip to content
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

Directly free structure managed by imemo tmpbuf #8493

Merged

Conversation

yui-knk
Copy link
Contributor

@yui-knk yui-knk commented Sep 21, 2023

NODE_ARGS, NODE_ARYPTN, NODE_FNDPTN manage memory of their structure by imemo tmpbuf Object.
However rb_ast_struct has reference to NODE. Then these memory can be freed directly when rb_ast_struct is freed.

This commit reduces parser's dependency on CRuby functions.

parse.y Outdated
Comment on lines 12725 to 12730
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
struct rb_args_info *args = ZALLOC(struct rb_args_info);
rb_imemo_tmpbuf_set_ptr(tmpbuf, args);
args->imemo = tmpbuf;
node = NEW_NODE(NODE_ARGS, 0, 0, args, &NULL_LOC);
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no longer using imemo, NODE should be created before ZALLOC to store it.
Otherwise that memory would leak if NEW_NODE failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. Changed the order of allocations.

NODE_ARGS, NODE_ARYPTN, NODE_FNDPTN manage memory of their
structure by imemo tmpbuf Object.
However rb_ast_struct has reference to NODE. Then these
memory can be freed directly when rb_ast_struct is freed.

This commit reduces parser's dependency on CRuby functions.
@yui-knk yui-knk force-pushed the remove_rb_imemo_tmpbuf_auto_free_pointer branch from 1e7d599 to e8efbdf Compare September 21, 2023 22:43
@yui-knk
Copy link
Contributor Author

yui-knk commented Sep 22, 2023

@nobu Can I ask you to check this PR again?

@yui-knk
Copy link
Contributor Author

yui-knk commented Sep 22, 2023

Thank you!

@yui-knk yui-knk merged commit fb7a2dd into ruby:master Sep 22, 2023
92 checks passed
@yui-knk yui-knk deleted the remove_rb_imemo_tmpbuf_auto_free_pointer branch September 22, 2023 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants