Skip to content

Commit 6240ab3

Browse files
colesburyvstinner
andauthored
Apply suggestions from code review
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent b090137 commit 6240ab3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pythoncapi_compat.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ static inline int PyUnstable_Object_IsUniquelyReferenced(PyObject *obj)
22322232
#endif
22332233

22342234
// gh-128926 added PyUnstable_TryIncRef() and PyUnstable_EnableTryIncRef() to
2235-
// Python 3.14.0a5. Adapted from _Py_TryIncref and _PyObject_SetMaybeWeakref.
2235+
// Python 3.14.0a5. Adapted from _Py_TryIncref() and _PyObject_SetMaybeWeakref().
22362236
#if PY_VERSION_HEX < 0x030E00A5
22372237
static inline int PyUnstable_TryIncRef(PyObject *op)
22382238
{
@@ -2243,9 +2243,11 @@ static inline int PyUnstable_TryIncRef(PyObject *op)
22432243
}
22442244
return 0;
22452245
#else
2246+
// _Py_TryIncrefFast()
22462247
uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local);
22472248
local += 1;
22482249
if (local == 0) {
2250+
// immortal
22492251
return 1;
22502252
}
22512253
if (_Py_IsOwnedByCurrentThread(op)) {
@@ -2256,6 +2258,8 @@ static inline int PyUnstable_TryIncRef(PyObject *op)
22562258
#endif
22572259
return 1;
22582260
}
2261+
2262+
// _Py_TryIncRefShared()
22592263
Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
22602264
for (;;) {
22612265
// If the shared refcount is zero and the object is either merged
@@ -2281,6 +2285,7 @@ static inline int PyUnstable_TryIncRef(PyObject *op)
22812285
static inline void PyUnstable_EnableTryIncRef(PyObject *op)
22822286
{
22832287
#ifdef Py_GIL_DISABLED
2288+
// _PyObject_SetMaybeWeakref()
22842289
if (_Py_IsImmortal(op)) {
22852290
return;
22862291
}

0 commit comments

Comments
 (0)