From bac7b3119504a3dedcf890b0a7f52db7e5616750 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Thu, 10 Sep 2026 17:20:53 -0700 Subject: [PATCH 1/2] 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. --- Doc/c-api/object.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index eedeb180c6b7606..5dcb8eca74a10d7 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -808,6 +808,13 @@ Object Protocol that this function doesn't call into the Python interpreter. This function cannot fail. + .. caution:: + + For objects where :c:expr:`Py_REFCNT(op) == 1` is always true this + function will return false when checked in a different thread than the + allocation. This can lead to subtle behavior change bugs between the + free-threaded and GIL-enabled builds (:gh:`156995`). + .. versionadded:: 3.14 .. c:function:: int PyUnstable_SetImmortal(PyObject *op) From 4cab0875c8ec522c821affc300c6d686a1de2938 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Fri, 11 Sep 2026 22:06:23 -0700 Subject: [PATCH 2/2] Drop non-descriptive setence --- Doc/c-api/object.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 5dcb8eca74a10d7..0d90cc9b7cf0ddb 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -812,8 +812,7 @@ Object Protocol For objects where :c:expr:`Py_REFCNT(op) == 1` is always true this function will return false when checked in a different thread than the - allocation. This can lead to subtle behavior change bugs between the - free-threaded and GIL-enabled builds (:gh:`156995`). + allocation. .. versionadded:: 3.14