@@ -371,14 +371,14 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
371371
372372/* Does this ref have an embedded refcount */
373373static 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) */
380380static 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)
399399static inline PyObject *
400400PyStackRef_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-
464458static inline _PyStackRef
465459PyStackRef_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)
474468static inline bool
475469PyStackRef_IsHeapSafe (_PyStackRef ref )
476470{
477- return !PyStackRef_HasCountAndMortal (ref );
471+ return !PyStackRef_IsCountedMortal (ref );
478472}
479473
480474static inline _PyStackRef
481475PyStackRef_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
494488PyStackRef_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
503497PyStackRef_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
512506PyStackRef_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 }
0 commit comments