Skip to content

Commit e4c7608

Browse files
committed
Use _Py_TryIncrefCompareStackRef and minor formatting
1 parent 57526e8 commit e4c7608

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Include/internal/pycore_cell.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ PyCell_GetRef(PyCellObject *cell)
4343
return res;
4444
}
4545

46-
static inline
47-
_PyStackRef _PyCell_GetStackRef(PyCellObject *cell)
46+
static inline _PyStackRef
47+
_PyCell_GetStackRef(PyCellObject *cell)
4848
{
4949
PyObject *value;
5050
#ifdef Py_GIL_DISABLED
5151
value = _Py_atomic_load_ptr(&cell->ob_ref);
52-
if (value != NULL) {
53-
if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)) {
54-
return (_PyStackRef){ .bits = (uintptr_t)value | Py_TAG_DEFERRED };
55-
}
56-
if (_Py_TryIncrefFast(value)) {
57-
return _PyStackRef_FromPyObjectSteal(value);
58-
}
52+
if (value == NULL) {
53+
return PyStackRef_NULL;
54+
}
55+
_PyStackRef ref;
56+
if (_Py_TryIncrefCompareStackRef(&cell->ob_ref, value, &ref)) {
57+
return ref;
5958
}
6059
#endif
6160
value = PyCell_GetRef(cell);

0 commit comments

Comments
 (0)