@@ -95,10 +95,16 @@ PyStackRef_IsNone(_PyStackRef ref)
9595 return _Py_stackref_get_object (ref ) == Py_None ;
9696}
9797
98+ static inline bool
99+ PyStackRef_IsTaggedInt (_PyStackRef ref )
100+ {
101+ return (ref .index & 1 ) == 1 ;
102+ }
103+
98104static inline PyObject *
99105_PyStackRef_AsPyObjectBorrow (_PyStackRef ref , const char * filename , int linenumber )
100106{
101- assert ((ref . index & 1 ) == 0 );
107+ assert (! PyStackRef_IsTaggedInt (ref ) );
102108 _Py_stackref_record_borrow (ref , filename , linenumber );
103109 return _Py_stackref_get_object (ref );
104110}
@@ -135,12 +141,6 @@ _PyStackRef_FromPyObjectImmortal(PyObject *obj, const char *filename, int linenu
135141}
136142#define PyStackRef_FromPyObjectImmortal (obj ) _PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj), __FILE__, __LINE__)
137143
138- static inline bool
139- PyStackRef_IsTaggedInt (_PyStackRef ref )
140- {
141- return (ref .index & 1 ) == 1 ;
142- }
143-
144144static inline void
145145_PyStackRef_CLOSE (_PyStackRef ref , const char * filename , int linenumber )
146146{
@@ -256,7 +256,7 @@ PyStackRef_TagInt(intptr_t i)
256256static inline intptr_t
257257PyStackRef_UntagInt (_PyStackRef i )
258258{
259- assert (( i . bits & Py_INT_TAG ) == Py_INT_TAG );
259+ assert (PyStackRef_IsTaggedInt ( i ) );
260260 intptr_t val = (intptr_t )i .bits ;
261261 return Py_ARITHMETIC_RIGHT_SHIFT (intptr_t , val , 2 );
262262}
@@ -286,6 +286,7 @@ static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
286286static inline PyObject *
287287PyStackRef_AsPyObjectBorrow (_PyStackRef stackref )
288288{
289+ assert (!PyStackRef_IsTaggedInt (stackref ));
289290 PyObject * cleared = ((PyObject * )((stackref ).bits & (~Py_TAG_BITS )));
290291 return cleared ;
291292}
0 commit comments