mirror of https://github.com/python/cpython
7e38e6745d
The `zip_next` function uses a common optimization technique for methods that generate tuples. The iterator maintains an internal reference to the returned tuple. When the method is called again, it checks if the internal tuple's reference count is 1. If so, the tuple can be reused. However, this approach is not safe under the free-threading build: after checking the reference count, another thread may perform the same check and also reuse the tuple. This can result in a double decref on the items of the replaced tuple and a double incref (memory leak) on the items of the tuple being set. This adds a function, `_PyObject_IsUniquelyReferenced` that encapsulates the stricter logic necessary for the free-threaded build: the internal tuple must be owned by the current thread, have a local refcount of one, and a shared refcount of zero. |
||
---|---|---|
.. | ||
__init__.py | ||
test_dict.py | ||
test_list.py | ||
test_monitoring.py | ||
test_slots.py | ||
test_str.py | ||
test_tokenize.py | ||
test_type.py | ||
test_zip.py |