@@ -238,6 +238,7 @@ PyStackRef_IsNullOrInt(_PyStackRef ref);
238
238
#else
239
239
240
240
#define Py_INT_TAG 3
241
+ #define Py_TAG_REFCNT 1
241
242
242
243
static inline bool
243
244
PyStackRef_IsTaggedInt (_PyStackRef i )
@@ -263,7 +264,7 @@ PyStackRef_UntagInt(_PyStackRef i)
263
264
264
265
#ifdef Py_GIL_DISABLED
265
266
266
- #define Py_TAG_DEFERRED (1)
267
+ #define Py_TAG_DEFERRED Py_TAG_REFCNT
267
268
268
269
#define Py_TAG_PTR ((uintptr_t)0)
269
270
#define Py_TAG_BITS ((uintptr_t)1)
@@ -441,14 +442,13 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
441
442
/* References to immortal objects always have their tag bit set to Py_TAG_REFCNT
442
443
* as they can (must) have their reclamation deferred */
443
444
444
- #define Py_TAG_BITS 1
445
- #define Py_TAG_REFCNT 1
445
+ #define Py_TAG_BITS 3
446
446
#if _Py_IMMORTAL_FLAGS != Py_TAG_REFCNT
447
447
# error "_Py_IMMORTAL_FLAGS != Py_TAG_REFCNT"
448
448
#endif
449
449
450
450
#define BITS_TO_PTR (REF ) ((PyObject *)((REF).bits))
451
- #define BITS_TO_PTR_MASKED (REF ) ((PyObject *)(((REF).bits) & (~Py_TAG_BITS )))
451
+ #define BITS_TO_PTR_MASKED (REF ) ((PyObject *)(((REF).bits) & (~Py_TAG_REFCNT )))
452
452
453
453
#define PyStackRef_NULL_BITS Py_TAG_REFCNT
454
454
static const _PyStackRef PyStackRef_NULL = { .bits = PyStackRef_NULL_BITS };
@@ -528,7 +528,7 @@ PyStackRef_FromPyObjectSteal(PyObject *obj)
528
528
{
529
529
assert (obj != NULL );
530
530
#if SIZEOF_VOID_P > 4
531
- unsigned int tag = obj -> ob_flags & Py_TAG_BITS ;
531
+ unsigned int tag = obj -> ob_flags & Py_TAG_REFCNT ;
532
532
#else
533
533
unsigned int tag = _Py_IsImmortal (obj ) ? Py_TAG_REFCNT : 0 ;
534
534
#endif
@@ -547,12 +547,6 @@ PyStackRef_FromPyObjectStealMortal(PyObject *obj)
547
547
return ref ;
548
548
}
549
549
550
- // Check if a stackref is exactly the same as another stackref, including the
551
- // the deferred bit. This can only be used safely if you know that the deferred
552
- // bits of `a` and `b` match.
553
- #define PyStackRef_IsExactly (a , b ) \
554
- (assert(((a).bits & Py_TAG_BITS) == ((b).bits & Py_TAG_BITS)), (a).bits == (b).bits)
555
-
556
550
static inline _PyStackRef
557
551
_PyStackRef_FromPyObjectNew (PyObject * obj )
558
552
{
@@ -604,7 +598,7 @@ PyStackRef_DUP(_PyStackRef ref)
604
598
static inline bool
605
599
PyStackRef_IsHeapSafe (_PyStackRef ref )
606
600
{
607
- return (ref .bits & Py_TAG_BITS ) == 0 || ref .bits == PyStackRef_NULL_BITS || _Py_IsImmortal (BITS_TO_PTR_MASKED (ref ));
601
+ return (ref .bits & Py_TAG_BITS ) != Py_TAG_REFCNT || ref .bits == PyStackRef_NULL_BITS || _Py_IsImmortal (BITS_TO_PTR_MASKED (ref ));
608
602
}
609
603
610
604
static inline _PyStackRef
@@ -679,7 +673,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
679
673
680
674
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
681
675
682
- #define PyStackRef_Is (a , b ) (((a).bits & (~Py_TAG_BITS )) == ((b).bits & (~Py_TAG_BITS )))
676
+ #define PyStackRef_Is (a , b ) (((a).bits & (~Py_TAG_REFCNT )) == ((b).bits & (~Py_TAG_REFCNT )))
683
677
684
678
685
679
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
0 commit comments