Skip to content

Commit bac7b31

Browse files
committed
gh-156995: Add caution around API behavior change
The subtle change between free-threading and GIL-enabled builds resulted in the `Py_REFCNT(op) == 1` `bytes` object inside `bytearray` was considered non-unique during `_PyBytes_Resize` which resulted in it being substitued for an immortal global rather than keeping the allocation only in free-threaded builds. The behavior has been fixed in `_PyBytes_Resize` but the hazard exists and was a part of a release blocking bug so urge caution around that case when porting.
1 parent 8f84787 commit bac7b31

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Doc/c-api/object.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,13 @@ Object Protocol
808808
that this function doesn't call into the Python interpreter. This function
809809
cannot fail.
810810
811+
.. caution::
812+
813+
For objects where :c:expr:`Py_REFCNT(op) == 1` is always true this
814+
function will return false when checked in a different thread than the
815+
allocation. This can lead to subtle behavior change bugs between the
816+
free-threaded and GIL-enabled builds (:gh:`156995`).
817+
811818
.. versionadded:: 3.14
812819
813820
.. c:function:: int PyUnstable_SetImmortal(PyObject *op)

0 commit comments

Comments
 (0)