-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-132775: Add _PyCode_VerifyStateless() #133221
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-132775: Add _PyCode_VerifyStateless() #133221
Conversation
!buildbot s390x RHEL8 LTO + PGO |
🤖 New build scheduled with the buildbot fleet by @ericsnowcurrently for commit d45c0e0 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133221%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
|
||
// The last instruction either returns or raises. We can take advantage | ||
// of that for a quick exit. | ||
_Py_CODEUNIT final = _Py_GetBaseCodeUnit(co, len-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the warning on Windows fixable on this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This looks to be failing on the iOS buildbot. test_code (test)
Doctest: test.test_code ... ok
======================================================================
ERROR: test_stateless (test.test_code.CodeTest.test_stateless) [(<function spam_N at 0x10fab5b50>, '(code)')]
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/buildbot/Library/Developer/XCTestDevices/3749308D-3FDE-41E4-B27C-3A4DD1FCF87A/data/Containers/Bundle/Application/40457EBF-BF74-4E58-B5DB-F52F8BC085A9/iOSTestbed.app/python/lib/python3.14/test/test_code.py", line 1049, in test_stateless
_testinternalcapi.verify_stateless_code(func.__code__)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
ValueError: only basic code objects are supported
======================================================================
ERROR: test_stateless (test.test_code.CodeTest.test_stateless) [(<function spam_C at 0x10fab4a10>, '(code)')]
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/buildbot/Library/Developer/XCTestDevices/3749308D-3FDE-41E4-B27C-3A4DD1FCF87A/data/Containers/Bundle/Application/40457EBF-BF74-4E58-B5DB-F52F8BC085A9/iOSTestbed.app/python/lib/python3.14/test/test_code.py", line 1049, in test_stateless
_testinternalcapi.verify_stateless_code(func.__code__)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
ValueError: only basic code objects are supported |
The test fails when it's run twice:
|
Looks like setting import sys
import _testinternalcapi
def foo():
pass
def trace_temporarily():
sys._getframe().f_trace_opcodes = True
sys.settrace(print)
sys.settrace(None)
sys._getframe().f_trace_opcodes = False
trace_temporarily()
_testinternalcapi.verify_stateless_code(foo.__code__)
foo()
_testinternalcapi.verify_stateless_code(foo.__code__) # fails In this case, |
I'm not sure what exactly "statelessness" is used for in the subinterpreters code. But, it looks like if it is to be useful, it either
Unfortunately, given the timing, I think this needs to be reverted for 3.14 :( |
@encukou Please could you open a revert PR? |
Will do. Resolving conflicts. |
…)" This reverts commit d270bb5. Note that the test functions in _code_definitions are not reverted.
Reverted in #133497. |
Thanks for jumping on this. I'll sort it out. FYI, the relevant code is |
…tateless() (pythongh-133221)" (python#133497)" This reverts commit 3c73cf5.
"Stateless" code is a function or code object which does not rely on external state or internal state. It may rely on arguments and
builtins, but not globals or a closure. I've left a comment in pycore_code.h that provides more detail.
We also add
_PyFunction_VerifyStateless()
. The new functions will be used in several later changes that facilitate "sharing" functions and code objects between interpreters.