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