@@ -187,16 +187,6 @@ _PyStackRef_FromPyObjectStealMortal(PyObject *obj, const char *filename, int lin
187187}
188188#define PyStackRef_FromPyObjectStealMortal (obj ) _PyStackRef_FromPyObjectStealMortal(_PyObject_CAST(obj), __FILE__, __LINE__)
189189
190- static inline bool
191- PyStackRef_IsMortal (_PyStackRef ref )
192- {
193- PyObject * obj = _Py_stackref_get_object (ref );
194- if (obj == NULL ) {
195- return false;
196- }
197- return _Py_IsImmortal (obj );
198- }
199-
200190static inline bool
201191PyStackRef_IsHeapSafe (_PyStackRef ref )
202192{
@@ -377,8 +367,12 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
377367// With GIL
378368
379369#define Py_TAG_BITS 3
380- #define Py_TAG_IMMORTAL _Py_IMMORTAL_FLAGS
381370#define Py_TAG_REFCNT 1
371+ #if _Py_IMMORTAL_FLAGS != Py_TAG_REFCNT
372+ # error "_Py_IMMORTAL_FLAGS != Py_TAG_REFCNT"
373+ #endif
374+ #define Py_TAG_IMMORTAL _Py_IMMORTAL_FLAGS
375+
382376#define BITS_TO_PTR (REF ) ((PyObject *)((REF).bits))
383377#define BITS_TO_PTR_MASKED (REF ) ((PyObject *)(((REF).bits) & (~Py_TAG_BITS)))
384378
@@ -402,7 +396,6 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
402396 PyObject * obj = BITS_TO_PTR_MASKED (ref );
403397 switch (tag ) {
404398 case 0 :
405- case Py_TAG_REFCNT :
406399 /* Can be immortal if object was made immortal after reference came into existence */
407400 assert (!_Py_IsStaticImmortal (obj ));
408401 break ;
@@ -422,8 +415,6 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
422415
423416#ifdef _WIN32
424417#define PyStackRef_IsUncountedMortal (REF ) (((REF).bits & Py_TAG_BITS) == 0)
425- #define PyStackRef_IsCountedMortal (REF ) (((REF).bits & Py_TAG_BITS) == Py_TAG_REFCNT)
426- #define PyStackRef_IsMortal (REF ) (((REF).bits & Py_TAG_BITS) != Py_TAG_IMMORTAL)
427418#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED
428419#else
429420/* Does this ref not have an embedded refcount and refer to a mortal object? */
@@ -433,20 +424,6 @@ PyStackRef_IsUncountedMortal(_PyStackRef ref)
433424 return (ref .bits & Py_TAG_BITS ) == 0 ;
434425}
435426
436- /* Does this ref have an embedded refcount and refer to a mortal object (NULL is not mortal)? */
437- static inline bool
438- PyStackRef_IsCountedMortal (_PyStackRef ref )
439- {
440- return (ref .bits & Py_TAG_BITS ) == Py_TAG_REFCNT ;
441- }
442-
443- /* Does this ref refer to a mortal object (NULL is not mortal) */
444- static inline bool
445- PyStackRef_IsMortal (_PyStackRef ref )
446- {
447- return (ref .bits & Py_TAG_BITS ) != Py_TAG_IMMORTAL ;
448- }
449-
450427static inline PyObject *
451428PyStackRef_AsPyObjectBorrow (_PyStackRef ref )
452429{
@@ -547,13 +524,13 @@ PyStackRef_DUP(_PyStackRef ref)
547524static inline bool
548525PyStackRef_IsHeapSafe (_PyStackRef ref )
549526{
550- return ! PyStackRef_IsCountedMortal (ref );
527+ return (ref . bits & Py_TAG_BITS ) == 0 || ref . bits == PyStackRef_NULL_BITS || _Py_IsImmortal ( BITS_TO_PTR_MASKED ( ref ) );
551528}
552529
553530static inline _PyStackRef
554531PyStackRef_MakeHeapSafe (_PyStackRef ref )
555532{
556- if (! PyStackRef_IsCountedMortal (ref )) {
533+ if (PyStackRef_IsHeapSafe (ref )) {
557534 return ref ;
558535 }
559536 PyObject * obj = BITS_TO_PTR_MASKED (ref );
0 commit comments