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

GH-94851: fix immortal objects refcounting in compiler #95040

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jul 20, 2022

@kumaraditya303 kumaraditya303 requested a review from corona10 July 20, 2022 07:04
@kumaraditya303 kumaraditya303 changed the title GH94851: fix immortal objects refcounting in compiler GH-94851: fix immortal objects refcounting in compiler Jul 20, 2022
@kumaraditya303 kumaraditya303 added the needs backport to 3.11 only security fixes label Jul 20, 2022
@corona10
Copy link
Member

corona10 commented Jul 20, 2022

@kumaraditya303 Thanks Kumar

I was also curious about this code also when you submitted the related patch before.

  1. It will be helpful to review if you can suggest reproducible code as you did before.
  2. There are several _Py_STR related codes that don't increase reference count when they are used.
    Should they be updated? and if yes, Would you like to submit the one-shot patch?

@kumaraditya303
Copy link
Contributor Author

There are several _Py_STR related codes that don't increase reference count when they are used.

it depends on its usage, if you are owning the object or returning it from a function then incref is required else it is not required.

@kumaraditya303
Copy link
Contributor Author

kumaraditya303 commented Jul 20, 2022

It will be helpful to review if you can suggest reproducible code as you did before.

If you follow the macro, it is capturing a reference to the new object so incref is required.

See comment : /* Same as ADDOP_LOAD_CONST, but steals a reference. */

@corona10
Copy link
Member

corona10 commented Jul 20, 2022

@kumaraditya303

a = 1
print(f'{a:d} {a:d}  {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d}')
./python.exe -X showrefcount tt.py
1 1  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[-1 refs, 0 blocks]

@kumaraditya303
Copy link
Contributor Author

a = 1
print(f'{a:d} {a:d}  {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d} {a:d}')
./python.exe -X showrefcount tt.py
1 1  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[-1 refs, 0 blocks]

Nice repro, thanks!

@corona10
Copy link
Member

And I checked that your patch fix this issue.

./python.exe -X showrefcount tt.py
1 1  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[0 refs, 0 blocks]

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

LGTM.

Please submit the reproducible code if possible it can reduce the reviewer's time and help understanding context :)
I know your patch is correct but reproducible code makes sure what your patch fixes exactly.

@corona10 corona10 merged commit 7476154 into python:main Jul 20, 2022
@miss-islington
Copy link
Contributor

Thanks @kumaraditya303 for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@kumaraditya303 kumaraditya303 deleted the fix-refcnt branch July 20, 2022 09:53
@bedevere-bot
Copy link

GH-95049 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 20, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 20, 2022
@corona10
Copy link
Member

I will merge backport patch after my dinner :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants