Skip to content

Commit 3997f3f

Browse files
Some addition to prev commit
1 parent 2cc17c7 commit 3997f3f

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

Include/internal/pycore_stackref.h

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ _PyStackRef_Borrow(_PyStackRef ref, const char *filename, int linenumber)
288288
}
289289
#define PyStackRef_Borrow(REF) _PyStackRef_Borrow((REF), __FILE__, __LINE__)
290290

291-
#define PyStackRef_CLEAR(REF) \
292-
do { \
293-
_PyStackRef *_tmp_op_ptr = &(REF); \
294-
_PyStackRef _tmp_old_op = (*_tmp_op_ptr); \
295-
*_tmp_op_ptr = PyStackRef_NULL; \
296-
PyStackRef_XCLOSE(_tmp_old_op); \
297-
} while (0)
298-
299291
static inline _PyStackRef
300292
_PyStackRef_FromPyObjectStealMortal(PyObject *obj, const char *filename, int linenumber)
301293
{
@@ -458,24 +450,16 @@ PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
458450
#define BITS_TO_PTR(REF) ((PyObject *)((REF).bits))
459451
#define BITS_TO_PTR_MASKED(REF) ((PyObject *)(((REF).bits) & (~Py_TAG_REFCNT)))
460452

461-
#define PyStackRef_NULL_BITS Py_TAG_REFCNT
462-
static const _PyStackRef PyStackRef_NULL = { .bits = PyStackRef_NULL_BITS };
453+
static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_REFCNT };
463454

464-
#define PyStackRef_IsNull(ref) ((ref).bits == PyStackRef_NULL_BITS)
465455
#define PyStackRef_True ((_PyStackRef){.bits = ((uintptr_t)&_Py_TrueStruct) | Py_TAG_REFCNT })
466456
#define PyStackRef_False ((_PyStackRef){.bits = ((uintptr_t)&_Py_FalseStruct) | Py_TAG_REFCNT })
467457
#define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) | Py_TAG_REFCNT })
468458

469-
#ifdef Py_GIL_DISABLED
470-
// Checks that mask out the deferred bit in the free threading build.
471-
#define PyStackRef_IsNone(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)&_Py_NoneStruct)
459+
#define PyStackRef_IsNull(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)NULL)
472460
#define PyStackRef_IsTrue(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)&_Py_TrueStruct)
473461
#define PyStackRef_IsFalse(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)&_Py_FalseStruct)
474-
#else
475-
#define PyStackRef_IsTrue(REF) ((REF).bits == (((uintptr_t)&_Py_TrueStruct) | Py_TAG_REFCNT))
476-
#define PyStackRef_IsFalse(REF) ((REF).bits == (((uintptr_t)&_Py_FalseStruct) | Py_TAG_REFCNT))
477-
#define PyStackRef_IsNone(REF) ((REF).bits == (((uintptr_t)&_Py_NoneStruct) | Py_TAG_REFCNT))
478-
#endif
462+
#define PyStackRef_IsNone(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)&_Py_NoneStruct)
479463

480464
#define PyStackRef_IsNullOrInt(stackref) (PyStackRef_IsNull(stackref) || PyStackRef_IsTaggedInt(stackref))
481465

@@ -612,14 +596,15 @@ PyStackRef_DUP(_PyStackRef ref)
612596
static inline bool
613597
PyStackRef_IsHeapSafe(_PyStackRef ref)
614598
{
615-
#ifdef Py_GIL_DISABLED
616-
if ((ref.bits & Py_TAG_BITS) != Py_TAG_REFCNT) {
599+
if ((ref.bits & Py_TAG_BITS) != Py_TAG_REFCNT || PyStackRef_IsNull(ref)) {
600+
// Tagged ints and ERROR are included.
617601
return true;
618602
}
619603
PyObject *obj = BITS_TO_PTR_MASKED(ref);
620-
return obj == NULL || _PyObject_HasDeferredRefcount(obj);
604+
#ifdef Py_GIL_DISABLED
605+
return _PyObject_HasDeferredRefcount(obj);
621606
#else
622-
return (ref.bits & Py_TAG_BITS) != Py_TAG_REFCNT || ref.bits == PyStackRef_NULL_BITS || _Py_IsImmortal(BITS_TO_PTR_MASKED(ref));
607+
return _Py_IsImmortal(obj);
623608
#endif
624609
}
625610

@@ -683,6 +668,13 @@ PyStackRef_XCLOSE(_PyStackRef ref)
683668
}
684669
#endif
685670

671+
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
672+
673+
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_REFCNT)) == ((b).bits & (~Py_TAG_REFCNT)))
674+
675+
676+
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
677+
686678
#define PyStackRef_CLEAR(REF) \
687679
do { \
688680
_PyStackRef *_tmp_op_ptr = &(REF); \
@@ -691,14 +683,6 @@ PyStackRef_XCLOSE(_PyStackRef ref)
691683
PyStackRef_XCLOSE(_tmp_old_op); \
692684
} while (0)
693685

694-
695-
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
696-
697-
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_REFCNT)) == ((b).bits & (~Py_TAG_REFCNT)))
698-
699-
700-
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
701-
702686
static inline PyTypeObject *
703687
PyStackRef_TYPE(_PyStackRef stackref) {
704688
if (PyStackRef_IsTaggedInt(stackref)) {

0 commit comments

Comments
 (0)