@@ -376,6 +376,19 @@ PyStackRef_IsNullOrInt(_PyStackRef ref);
376376
377377static const _PyStackRef PyStackRef_ERROR = { .bits = Py_TAG_INVALID };
378378
379+ static inline PyObject *
380+ _PyStackRef_AsTuple (_PyStackRef ref , PyObject * op )
381+ {
382+ int flags = ref .bits & Py_TAG_BITS ;
383+ #ifdef Py_GIL_DISABLED
384+ if (_Py_IsImmortal (op )) {
385+ // Do not check flags on immortal objects in the free threading build.
386+ flags = -1 ;
387+ }
388+ #endif
389+ return Py_BuildValue ("(ni)" , Py_REFCNT (op ), flags );
390+ }
391+
379392/* Wrap a pointer in a stack ref.
380393 * The resulting stack reference is not safe and should only be used
381394 * in the interpreter to pass values from one uop to another.
@@ -476,13 +489,6 @@ static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
476489
477490#define PyStackRef_IsNullOrInt (stackref ) (PyStackRef_IsNull(stackref) || PyStackRef_IsTaggedInt(stackref))
478491
479- static inline PyObject *
480- _PyStackRef_AsTuple (_PyStackRef ref , PyObject * op )
481- {
482- // Do not check StackRef flags in the free threading build.
483- return Py_BuildValue ("(ni)" , Py_REFCNT (op ), -1 );
484- }
485-
486492static inline PyObject *
487493PyStackRef_AsPyObjectBorrow (_PyStackRef stackref )
488494{
@@ -667,13 +673,6 @@ static const _PyStackRef PyStackRef_NULL = { .bits = PyStackRef_NULL_BITS };
667673#define PyStackRef_IsFalse (REF ) ((REF).bits == (((uintptr_t)&_Py_FalseStruct) | Py_TAG_REFCNT))
668674#define PyStackRef_IsNone (REF ) ((REF).bits == (((uintptr_t)&_Py_NoneStruct) | Py_TAG_REFCNT))
669675
670- static inline PyObject *
671- _PyStackRef_AsTuple (_PyStackRef ref , PyObject * op )
672- {
673- int flags = ref .bits & Py_TAG_BITS ;
674- return Py_BuildValue ("(ni)" , Py_REFCNT (op ), flags );
675- }
676-
677676#ifdef Py_DEBUG
678677
679678static inline void PyStackRef_CheckValid (_PyStackRef ref ) {
0 commit comments