gh-132775: Add _PyCode_VerifyStateless()#133221
gh-132775: Add _PyCode_VerifyStateless()#133221ericsnowcurrently merged 12 commits intopython:mainfrom
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.
Is the warning on Windows fixable on this PR?
|
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__) # failsIn 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.
The problem we're fixing here is that we were using PyDict_Size() on "defaults", which it is actually a tuple. We're also adding some explicit type checks. This is a follow-up to pythongh-133221/pythongh-133528. (cherry picked from commit dafd141) Co-authored-by: Eric Snow <[email protected]>
gh-132775: Fix _PyFunctIon_VerifyStateless() () The problem we're fixing here is that we were using PyDict_Size() on "defaults", which it is actually a tuple. We're also adding some explicit type checks. This is a follow-up to gh-133221/gh-133528. (cherry picked from commit dafd141, AKA gh-134900) Co-authored-by: Eric Snow <[email protected]>
"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.
…33528) This reverts commit 3c73cf5 (pythongh-133497), which itself reverted the original commit d270bb5 (pythongh-133221). We reverted the original change due to failing android tests. The checks in _PyCode_CheckNoInternalState() were too strict, so we've relaxed them.
The problem we're fixing here is that we were using PyDict_Size() on "defaults", which it is actually a tuple. We're also adding some explicit type checks. This is a follow-up to pythongh-133221/pythongh-133528.
The problem we're fixing here is that we were using PyDict_Size() on "defaults", which it is actually a tuple. We're also adding some explicit type checks. This is a follow-up to pythongh-133221/pythongh-133528.
"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.