gh-135443: Sometimes Fall Back to __main__.__dict__ For Globals#135491
Conversation
| if (_PyEval_GetFrame() != NULL) { | ||
| locals = _PyEval_GetFrameLocals(); | ||
| } | ||
| PyThreadState *tstate = _PyThreadState_GET(); | ||
| locals = _PyEval_GetGlobalsFromRunningMain(tstate); |
There was a problem hiding this comment.
_PyEval_GetFrameLocals() returns a new reference (leak), which is overwritten by _PyEval_GetGlobalsFromRunningMain(). Thus the fallback mechanism looks to be missing.
The same goes for builtin_vars().
| interp.call(func, op, 'eggs!') | ||
|
|
||
| def test_callable_requires_frame(self): | ||
| # There are various functions tha require a current frame. |
| notshareable = [ | ||
| globals, | ||
| locals, | ||
| vars, | ||
| ] |
There was a problem hiding this comment.
If "notshareable" here means that the result of the functions cannot be pickled, could NotShareableError differentiate the round-trip in the future? Also, interpreters.is_shareable() returns False for both globals and dir, which might be confusing at first.
|
🤖 New build scheduled with the buildbot fleet by @ericsnowcurrently for commit c93f890 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135491%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…pythongh-135491) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables. (cherry picked from commit a450a0d) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
|
GH-135593 is a backport of this pull request to the 3.14 branch. |
gh-135593) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables. (cherry picked from commit a450a0d, AKA gh-135491) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
…pythongh-135491) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables.
…pythongh-135491) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables.
…pythongh-135491) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables.
…pythongh-135491) For several builtin functions, we now fall back to __main__.__dict__ for the globals when there is no current frame and _PyInterpreterState_IsRunningMain() returns true. This allows those functions to be run with Interpreter.call(). The affected builtins: * exec() * eval() * globals() * locals() * vars() * dir() We take a similar approach with "stateless" functions, which don't use any global variables.
For several builtin functions, we now fall back to
__main__.__dict__for the globalswhen there is no current frame and
_PyInterpreterState_IsRunningMain()returnstrue. This allows those functions to be run with
Interpreter.call().The affected builtins:
exec()eval()globals()locals()vars()dir()