Skip to content

Commit d744179

Browse files
committed
Rename functions and add comment
1 parent 37f1e18 commit d744179

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Include/internal/pycore_stackref.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,12 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
366366

367367
// With GIL
368368

369-
#define Py_TAG_BITS 3
369+
/* References to immortal objects always have their tag bit set to Py_TAG_REFCNT
370+
* as they can (must) have their reclamation deferred */
371+
372+
#define Py_TAG_BITS 1
370373
#define Py_TAG_REFCNT 1
371-
#if Py_TAG_REFCNT != Py_TAG_REFCNT
374+
#if _Py_IMMORTAL_FLAGS != Py_TAG_REFCNT
372375
# error "_Py_IMMORTAL_FLAGS != Py_TAG_REFCNT"
373376
#endif
374377

@@ -413,12 +416,12 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
413416
#endif
414417

415418
#ifdef _WIN32
416-
#define PyStackRef_IsUncountedMortal(REF) (((REF).bits & Py_TAG_BITS) == 0)
419+
#define PyStackRef_RefcountOnObject(REF) (((REF).bits & Py_TAG_BITS) == 0)
417420
#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED
418421
#else
419-
/* Does this ref not have an embedded refcount and refer to a mortal object? */
422+
/* Does this ref not have an embedded refcount and thus not refer to a declared immmortal object? */
420423
static inline int
421-
PyStackRef_IsUncountedMortal(_PyStackRef ref)
424+
PyStackRef_RefcountOnObject(_PyStackRef ref)
422425
{
423426
return (ref.bits & Py_TAG_BITS) == 0;
424427
}
@@ -433,7 +436,7 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
433436
static inline PyObject *
434437
PyStackRef_AsPyObjectSteal(_PyStackRef ref)
435438
{
436-
if (PyStackRef_IsUncountedMortal(ref)) {
439+
if (PyStackRef_RefcountOnObject(ref)) {
437440
return BITS_TO_PTR(ref);
438441
}
439442
else {
@@ -504,16 +507,16 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
504507
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_REFCNT};
505508
}
506509

507-
/* WARNING: This macro evaluates its argument twice */
510+
/* WARNING: This macro evaluates its argument more than once */
508511
#ifdef _WIN32
509512
#define PyStackRef_DUP(REF) \
510-
(PyStackRef_IsUncountedMortal(REF) ? (Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
513+
(PyStackRef_RefcountOnObject(REF) ? (Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
511514
#else
512515
static inline _PyStackRef
513516
PyStackRef_DUP(_PyStackRef ref)
514517
{
515518
assert(!PyStackRef_IsNull(ref));
516-
if (PyStackRef_IsUncountedMortal(ref)) {
519+
if (PyStackRef_RefcountOnObject(ref)) {
517520
Py_INCREF_MORTAL(BITS_TO_PTR(ref));
518521
}
519522
return ref;
@@ -543,14 +546,14 @@ PyStackRef_MakeHeapSafe(_PyStackRef ref)
543546
#define PyStackRef_CLOSE(REF) \
544547
do { \
545548
_PyStackRef _temp = (REF); \
546-
if (PyStackRef_IsUncountedMortal(_temp)) Py_DECREF_MORTAL(BITS_TO_PTR(_temp)); \
549+
if (PyStackRef_RefcountOnObject(_temp)) Py_DECREF_MORTAL(BITS_TO_PTR(_temp)); \
547550
} while (0)
548551
#else
549552
static inline void
550553
PyStackRef_CLOSE(_PyStackRef ref)
551554
{
552555
assert(!PyStackRef_IsNull(ref));
553-
if (PyStackRef_IsUncountedMortal(ref)) {
556+
if (PyStackRef_RefcountOnObject(ref)) {
554557
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
555558
}
556559
}
@@ -560,7 +563,7 @@ static inline void
560563
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
561564
{
562565
assert(!PyStackRef_IsNull(ref));
563-
if (PyStackRef_IsUncountedMortal(ref)) {
566+
if (PyStackRef_RefcountOnObject(ref)) {
564567
Py_DECREF_MORTAL_SPECIALIZED(BITS_TO_PTR(ref), destruct);
565568
}
566569
}
@@ -572,7 +575,7 @@ static inline void
572575
PyStackRef_XCLOSE(_PyStackRef ref)
573576
{
574577
assert(ref.bits != 0);
575-
if (PyStackRef_IsUncountedMortal(ref)) {
578+
if (PyStackRef_RefcountOnObject(ref)) {
576579
assert(!PyStackRef_IsNull(ref));
577580
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
578581
}
@@ -592,7 +595,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
592595

593596
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
594597

595-
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS)))
598+
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_REFCNT)) == ((b).bits & (~Py_TAG_REFCNT)))
596599

597600
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
598601

0 commit comments

Comments
 (0)