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

cgen: fix autofree inserting string declarations for multiple functions calls #18723

Merged
merged 5 commits into from Jul 3, 2023

Conversation

walkingdevel
Copy link
Contributor

@walkingdevel walkingdevel commented Jun 30, 2023

Fixes #17768

image

🤖 Generated by Copilot at cc2b0b5

Improved the autofree feature for string operations and function calls in the V compiler. Renamed a variable and a comment, updated the statement positions, and added a valgrind test.

🤖 Generated by Copilot at cc2b0b5

  • Rename last_stmt_pos to stmt_before_call_expr_pos in cgen.v to avoid confusion with Gen.last_stmt_pos and clarify its role in autofree feature (link)
  • Use stmt_before_call_expr_pos instead of last_stmt_pos in g.insert_at call in cgen.v to insert string declarations before call expressions that may produce strings to be freed (link)
  • Update g.stmt_path_pos array in g.insert_at method in text_manipulation.v to account for added line of code and maintain correct positions for autofree feature (link)
  • Change comment /*af arg*/ to /*autofree arg*/ in fn.v to make it more consistent and clear (link)
  • Add test function color_code_to_rgb and call it with sample input in multiple_fn_calls.v to check for memory leaks and errors with valgrind and autofree feature (link)

@walkingdevel walkingdevel marked this pull request as draft June 30, 2023 22:48
@walkingdevel walkingdevel marked this pull request as ready for review July 2, 2023 18:20
@walkingdevel
Copy link
Contributor Author

@spytheman, maybe I'll do this PR without tests? I fixed the main problem, but memory leaks that are not related to this PR do not allow me to finish.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Excellent work.

@spytheman
Copy link
Member

@spytheman, maybe I'll do this PR without tests? I fixed the main problem, but memory leaks that are not related to this PR do not allow me to finish.

Edit skip_valgrind_files in vlib/v/slow_tests/valgrind/valgrind_test.v and add vlib/v/slow_tests/valgrind/multiple_fn_calls.v there.
That will guarantee that it will compile with -autofree, to prevent regressions, but without running it under valgrind after that.

@spytheman spytheman changed the title autofree: fix inserting string declarations for multiple functions calls cgen: fix autofree inserting string declarations for multiple functions calls Jul 2, 2023
@walkingdevel
Copy link
Contributor Author

@spytheman, maybe I'll do this PR without tests? I fixed the main problem, but memory leaks that are not related to this PR do not allow me to finish.

Edit skip_valgrind_files in vlib/v/slow_tests/valgrind/valgrind_test.v and add vlib/v/slow_tests/valgrind/multiple_fn_calls.v there. That will guarantee that it will compile with -autofree, to prevent regressions, but without running it under valgrind after that.

Thank you!

@spytheman spytheman merged commit c48ae86 into vlang:master Jul 3, 2023
49 checks passed
@walkingdevel walkingdevel deleted the fix-autofree-cgen branch July 3, 2023 10:03
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.

cgen: -autofree fails
2 participants