@@ -63,11 +63,11 @@ extern void _Py_stackref_associate(PyInterpreterState *interp, PyObject *obj, _P
6363
6464static const _PyStackRef PyStackRef_NULL = { .index = 0 };
6565
66- #define PyStackRef_None ((_PyStackRef){ .index = 1 } )
67- #define PyStackRef_False ((_PyStackRef){ .index = 2 })
68- #define PyStackRef_True ((_PyStackRef){ .index = 3 })
66+ #define PyStackRef_None ((_PyStackRef){ .index = 2 } )
67+ #define PyStackRef_False ((_PyStackRef){ .index = 4 })
68+ #define PyStackRef_True ((_PyStackRef){ .index = 6 })
6969
70- #define LAST_PREDEFINED_STACKREF_INDEX 3
70+ #define LAST_PREDEFINED_STACKREF_INDEX 6
7171
7272static inline int
7373PyStackRef_IsNull (_PyStackRef ref )
@@ -96,6 +96,7 @@ PyStackRef_IsNone(_PyStackRef ref)
9696static inline PyObject *
9797_PyStackRef_AsPyObjectBorrow (_PyStackRef ref , const char * filename , int linenumber )
9898{
99+ assert ((ref .index & 1 ) == 0 );
99100 _Py_stackref_record_borrow (ref , filename , linenumber );
100101 return _Py_stackref_get_object (ref );
101102}
@@ -132,31 +133,45 @@ _PyStackRef_FromPyObjectImmortal(PyObject *obj, const char *filename, int linenu
132133}
133134#define PyStackRef_FromPyObjectImmortal (obj ) _PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj), __FILE__, __LINE__)
134135
136+ static inline bool
137+ is_tagged_int (_PyStackRef ref )
138+ {
139+ return (ref .index & 1 ) == 1 ;
140+ }
141+
135142static inline void
136143_PyStackRef_CLOSE (_PyStackRef ref , const char * filename , int linenumber )
137144{
145+ if (is_tagged_int (ref )) {
146+ return ;
147+ }
138148 PyObject * obj = _Py_stackref_close (ref , filename , linenumber );
139149 Py_DECREF (obj );
140150}
141151#define PyStackRef_CLOSE (REF ) _PyStackRef_CLOSE((REF), __FILE__, __LINE__)
142152
153+
143154static inline void
144155_PyStackRef_XCLOSE (_PyStackRef ref , const char * filename , int linenumber )
145156{
146157 if (PyStackRef_IsNull (ref )) {
147158 return ;
148159 }
149- PyObject * obj = _Py_stackref_close (ref , filename , linenumber );
150- Py_DECREF (obj );
160+ _PyStackRef_CLOSE (ref , filename , linenumber );
151161}
152162#define PyStackRef_XCLOSE (REF ) _PyStackRef_XCLOSE((REF), __FILE__, __LINE__)
153163
154164static inline _PyStackRef
155165_PyStackRef_DUP (_PyStackRef ref , const char * filename , int linenumber )
156166{
157- PyObject * obj = _Py_stackref_get_object (ref );
158- Py_INCREF (obj );
159- return _Py_stackref_create (obj , filename , linenumber );
167+ if (ref .index & 1 ) {
168+ return ref ;
169+ }
170+ else {
171+ PyObject * obj = _Py_stackref_get_object (ref );
172+ Py_INCREF (obj );
173+ return _Py_stackref_create (obj , filename , linenumber );
174+ }
160175}
161176#define PyStackRef_DUP (REF ) _PyStackRef_DUP(REF, __FILE__, __LINE__)
162177
@@ -210,8 +225,15 @@ _PyStackRef_FromPyObjectNewMortal(PyObject *obj, const char *filename, int linen
210225
211226extern int PyStackRef_Is (_PyStackRef a , _PyStackRef b );
212227
228+ extern bool PyStackRef_IsTaggedInt (_PyStackRef ref );
229+
230+ extern intptr_t PyStackRef_UntagInt (_PyStackRef ref );
231+
213232extern _PyStackRef PyStackRef_TagInt (intptr_t i );
214233
234+ extern bool
235+ PyStackRef_IsNullOrInt (_PyStackRef ref );
236+
215237#else
216238
217239#define Py_INT_TAG 3
0 commit comments