]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-115999: Add free-threaded specialization for `UNPACK_SEQUENCE` (#126600)
authorKirill Podoprigora <kirill.bast9@mail.ru>
Fri, 22 Nov 2024 17:00:35 +0000 (19:00 +0200)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2024 17:00:35 +0000 (19:00 +0200)
commit27486c3365a1f628e2df9a0e88c7c51706a1282e
tree1bca57831f3a466325c48b94d1c0f52f977992f5
parent5ba67af006079915af0a1312735efc40fa36c4f3
gh-115999: Add free-threaded specialization for `UNPACK_SEQUENCE` (#126600)

Add free-threaded specialization for `UNPACK_SEQUENCE` opcode.
`UNPACK_SEQUENCE_TUPLE/UNPACK_SEQUENCE_TWO_TUPLE` are already thread safe since tuples are immutable.
`UNPACK_SEQUENCE_LIST` is not thread safe because of nature of lists (there is nothing preventing another thread from adding items to or removing them the list while the instruction is executing). To achieve thread safety we add a critical section to the implementation of `UNPACK_SEQUENCE_LIST`, especially around the parts where we check the size of the list and push items onto the stack.

---------

Co-authored-by: Matt Page <mpage@meta.com>
Co-authored-by: mpage <mpage@cs.stanford.edu>
Include/internal/pycore_opcode_metadata.h
Include/internal/pycore_uop_metadata.h
Lib/test/test_opcache.py
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h
Python/specialize.c