Skip to content

Commit d3da41c

Browse files
committed
Clarifications
1 parent 26e7868 commit d3da41c

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

Include/internal/pycore_stackref.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
371371

372372
/* Does this ref have an embedded refcount */
373373
static inline int
374-
PyStackRef_HasCount(_PyStackRef ref)
374+
PyStackRef_IsUncountedMortal(_PyStackRef ref)
375375
{
376-
return ref.bits & Py_TAG_REFCNT;
376+
return (ref.bits & Py_TAG_BITS) == 0;
377377
}
378378

379379
/* Does this ref have an embedded refcount and refer to a mortal object (NULL is not mortal) */
380380
static inline bool
381-
PyStackRef_HasCountAndMortal(_PyStackRef ref)
381+
PyStackRef_IsCountedMortal(_PyStackRef ref)
382382
{
383383
return (ref.bits & Py_TAG_BITS) == Py_TAG_REFCNT;
384384
}
@@ -399,11 +399,11 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
399399
static inline PyObject *
400400
PyStackRef_AsPyObjectSteal(_PyStackRef ref)
401401
{
402-
if (PyStackRef_HasCount(ref)) {
403-
return Py_NewRef(BITS_TO_PTR_MASKED(ref));
402+
if (PyStackRef_IsUncountedMortal(ref)) {
403+
return BITS_TO_PTR(ref);
404404
}
405405
else {
406-
return BITS_TO_PTR(ref);
406+
return Py_NewRef(BITS_TO_PTR_MASKED(ref));
407407
}
408408
}
409409

@@ -455,17 +455,11 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
455455
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_IMMORTAL};
456456
}
457457

458-
static inline _PyStackRef
459-
PyStackRef_WithCount(_PyStackRef ref)
460-
{
461-
return (_PyStackRef){ .bits = ref.bits | Py_TAG_REFCNT };
462-
}
463-
464458
static inline _PyStackRef
465459
PyStackRef_DUP(_PyStackRef ref)
466460
{
467461
assert(!PyStackRef_IsNull(ref));
468-
if (!PyStackRef_HasCount(ref)) {
462+
if (PyStackRef_IsUncountedMortal(ref)) {
469463
Py_INCREF_MORTAL(BITS_TO_PTR(ref));
470464
}
471465
return ref;
@@ -474,13 +468,13 @@ PyStackRef_DUP(_PyStackRef ref)
474468
static inline bool
475469
PyStackRef_IsHeapSafe(_PyStackRef ref)
476470
{
477-
return !PyStackRef_HasCountAndMortal(ref);
471+
return !PyStackRef_IsCountedMortal(ref);
478472
}
479473

480474
static inline _PyStackRef
481475
PyStackRef_MakeHeapSafe(_PyStackRef ref)
482476
{
483-
if (!PyStackRef_HasCountAndMortal(ref)) {
477+
if (!PyStackRef_IsCountedMortal(ref)) {
484478
return ref;
485479
}
486480
PyObject *obj = BITS_TO_PTR_MASKED(ref);
@@ -494,7 +488,7 @@ static inline void
494488
PyStackRef_CLOSE(_PyStackRef ref)
495489
{
496490
assert(!PyStackRef_IsNull(ref));
497-
if (!PyStackRef_HasCount(ref)) {
491+
if (PyStackRef_IsUncountedMortal(ref)) {
498492
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
499493
}
500494
}
@@ -503,7 +497,7 @@ static inline void
503497
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
504498
{
505499
assert(!PyStackRef_IsNull(ref));
506-
if (!PyStackRef_HasCount(ref)) {
500+
if (PyStackRef_IsUncountedMortal(ref)) {
507501
Py_DECREF_MORTAL_SPECIALIZED(BITS_TO_PTR(ref), destruct);
508502
}
509503
}
@@ -512,7 +506,7 @@ static inline void
512506
PyStackRef_XCLOSE(_PyStackRef ref)
513507
{
514508
assert(ref.bits != 0);
515-
if (!PyStackRef_HasCount(ref)) {
509+
if (PyStackRef_IsUncountedMortal(ref)) {
516510
assert(!PyStackRef_IsNull(ref));
517511
Py_DECREF_MORTAL(BITS_TO_PTR(ref));
518512
}

Python/generated_cases.c.h

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/analyzer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
593593
"PyStackRef_FromPyObjectSteal",
594594
"PyStackRef_IsExactly",
595595
"PyStackRef_FromPyObjectStealMortal",
596-
"PyStackRef_HasCount",
597596
"PyStackRef_IsNone",
598597
"PyStackRef_Is",
599598
"PyStackRef_IsHeapSafe",

0 commit comments

Comments
 (0)