@@ -5,7 +5,7 @@ extern "C" {
5
5
#endif
6
6
7
7
// Define this to get precise tracking of stackrefs.
8
- // #define Py_STACKREF_DEBUG 1
8
+ #define Py_STACKREF_DEBUG 1
9
9
10
10
#ifndef Py_BUILD_CORE
11
11
# error "this header requires Py_BUILD_CORE define"
@@ -144,6 +144,16 @@ PyStackRef_CLOSE(_PyStackRef ref)
144
144
Py_DECREF (obj );
145
145
}
146
146
147
+ static inline void
148
+ PyStackRef_XCLOSE (_PyStackRef ref )
149
+ {
150
+ if (PyStackRef_IsNull (ref )) {
151
+ return ;
152
+ }
153
+ PyObject * obj = _Py_stackref_close (ref );
154
+ Py_DECREF (obj );
155
+ }
156
+
147
157
static inline _PyStackRef
148
158
_PyStackRef_DUP (_PyStackRef ref , const char * filename , int linenumber )
149
159
{
@@ -153,7 +163,47 @@ _PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
153
163
}
154
164
#define PyStackRef_DUP (REF ) _PyStackRef_DUP(REF, __FILE__, __LINE__)
155
165
156
- #define PyStackRef_CLOSE_SPECIALIZED (stackref , dealloc ) PyStackRef_CLOSE(stackref)
166
+ extern void PyStackRef_CLOSE_SPECIALIZED (_PyStackRef ref , destructor destruct );
167
+
168
+ static inline _PyStackRef
169
+ PyStackRef_MakeHeapSafe (_PyStackRef ref )
170
+ {
171
+ return ref ;
172
+ }
173
+
174
+ #define PyStackRef_CLEAR (REF ) \
175
+ do { \
176
+ _PyStackRef *_tmp_op_ptr = &(REF); \
177
+ _PyStackRef _tmp_old_op = (*_tmp_op_ptr); \
178
+ *_tmp_op_ptr = PyStackRef_NULL; \
179
+ PyStackRef_XCLOSE(_tmp_old_op); \
180
+ } while (0)
181
+
182
+
183
+ static inline _PyStackRef
184
+ _PyStackRef_FromPyObjectStealMortal (PyObject * obj , const char * filename , int linenumber )
185
+ {
186
+ assert (!_Py_IsImmortal (obj ));
187
+ return _Py_stackref_create (obj , filename , linenumber );
188
+ }
189
+ #define PyStackRef_FromPyObjectStealMortal (obj ) _PyStackRef_FromPyObjectStealMortal(_PyObject_CAST(obj), __FILE__, __LINE__)
190
+
191
+ static inline bool
192
+ PyStackRef_IsMortal (_PyStackRef ref )
193
+ {
194
+ PyObject * obj = _Py_stackref_get_object (ref );
195
+ if (obj == NULL ) {
196
+ return false;
197
+ }
198
+ return _Py_IsImmortal (obj );
199
+ }
200
+
201
+ static inline int
202
+ PyStackRef_IsHeapSafe (_PyStackRef ref )
203
+ {
204
+ return 1 ;
205
+ }
206
+
157
207
158
208
#else
159
209
@@ -512,27 +562,20 @@ PyStackRef_XCLOSE(_PyStackRef ref)
512
562
}
513
563
}
514
564
515
- #define PyStackRef_CLEAR (REF ) \
516
- do { \
517
- _PyStackRef *_tmp_op_ptr = &(REF); \
518
- _PyStackRef _tmp_old_op = (*_tmp_op_ptr); \
519
- *_tmp_op_ptr = PyStackRef_NULL; \
520
- PyStackRef_XCLOSE(_tmp_old_op); \
521
- } while (0)
522
565
523
566
#endif // Py_GIL_DISABLED
524
567
525
568
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
526
569
527
570
#define PyStackRef_Is (a , b ) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS)))
528
571
529
- // Converts a PyStackRef back to a PyObject *, converting the
530
- // stackref to a new reference.
531
- #define PyStackRef_AsPyObjectNew (stackref ) Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref))
572
+ #endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
532
573
533
574
#define PyStackRef_TYPE (stackref ) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref))
534
575
535
- #endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
576
+ // Converts a PyStackRef back to a PyObject *, converting the
577
+ // stackref to a new reference.
578
+ #define PyStackRef_AsPyObjectNew (stackref ) Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref))
536
579
537
580
// StackRef type checks
538
581
0 commit comments