Skip to content

gh-118934: Make PyEval_GetLocals return borrowed reference - #119769

Merged
gaogaotiantian merged 10 commits into
python:mainfrom
gaogaotiantian:fix-getlocals
Jul 16, 2024
Merged

gh-118934: Make PyEval_GetLocals return borrowed reference#119769
gaogaotiantian merged 10 commits into
python:mainfrom
gaogaotiantian:fix-getlocals

Conversation

@gaogaotiantian

@gaogaotiantiangaogaotiantian commented May 30, 2024

Copy link
Copy Markdown
Member

Per discussion with @markshannon in Pittsburgh, we simulate what we did pre-PEP667. We store the locals dict in frame->f_locals so that we can return a borrowed reference. The frame->f_locals will be cleared when the frame is released. This way we can keep the behavior of PyEval_GetLocals().

@gaogaotiantiangaogaotiantian added 3.13 bugs and security fixes needs backport to 3.13 bugs and security fixes and removed 3.13 bugs and security fixes labels May 30, 2024
@gaogaotiantian
gaogaotiantian marked this pull request as draft May 30, 2024 17:30
@gaogaotiantian

Copy link
Copy Markdown
MemberAuthor

Just realized this will overwrite f_locals when it's called inside a comprehension of a non-optimized scope. We might have to use a new member in FrameObject to store this.

@colesburycolesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few formatting suggestions and a question about the return value

Comment threadPython/ceval.c Outdated
Comment threadPython/ceval.c Outdated
Comment threadPython/ceval.c
Comment threadPython/ceval.c Outdated
Comment threadPython/ceval.c Outdated
Comment threadPython/ceval.c Outdated
@ncoghlan

Copy link
Copy Markdown
Contributor

@gaogaotiantian I merged the suggestion that reverts back to the Python 3.12 semantics, so we can get a CI run on that version of the refleak fix.

@ncoghlanncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gaogaotiantian CI is happy with going back to the Python 3.12 behaviour, so if you're happy I think this is good to merge for the final beta.

@miss-islington-app

Copy link
Copy Markdown

Thanks @gaogaotiantian for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@gaogaotiantian
gaogaotiantian deleted the fix-getlocals branch July 16, 2024 19:17
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 16, 2024
…honGH-119769)
(cherry picked from commit e65cb4c)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
@bedevere-app

Copy link
Copy Markdown

GH-121869 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Jul 16, 2024
ncoghlan added a commit that referenced this pull request Jul 18, 2024
…-119769) (#121869)
gh-118934: Make PyEval_GetLocals return borrowed reference (GH-119769)
(cherry picked from commit e65cb4c)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Clang Installed 3.13 has failed when building commit 233ed46.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#builders/1392/builds/214) and take a look at the build logs.
  4. Check if the failure is related to this commit (233ed46) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#builders/1392/builds/214

Failed tests:

  • test_pyrepl

Failed subtests:

  • test_inspect_keeps_globals_from_inspected_file - test.test_pyrepl.test_pyrepl.TestMain.test_inspect_keeps_globals_from_inspected_file
  • test_inspect_keeps_globals_from_inspected_module - test.test_pyrepl.test_pyrepl.TestMain.test_inspect_keeps_globals_from_inspected_module

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.clang-installed/build/target/lib/python3.13/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: FOO= not found in output
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.clang-installed/build/target/lib/python3.13/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: __name__= not found in output
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.clang-installed/build/target/lib/python3.13/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: __package__= not found in output

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora LTO + PGO 3.13 has failed when building commit 233ed46.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#builders/1511/builds/215) and take a look at the build logs.
  4. Check if the failure is related to this commit (233ed46) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#builders/1511/builds/215

Failed tests:

  • test_pyrepl

Failed subtests:

  • test_inspect_keeps_globals_from_inspected_module - test.test_pyrepl.test_pyrepl.TestMain.test_inspect_keeps_globals_from_inspected_module

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.lto-pgo/build/Lib/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: __package__= not found in output
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.lto-pgo/build/Lib/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: __file__= not found in output
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.13.edelsohn-fedora-z.lto-pgo/build/Lib/test/test_pyrepl/test_pyrepl.py", line 995, in _run_repl_globals_testself.fail(f"{var}= not found in output")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: FOO= not found in output

Sign up for freeto 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.

4 participants

@gaogaotiantian@ncoghlan@bedevere-bot@colesbury