summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_stackref.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/internal/pycore_stackref.h')
-rw-r--r--Include/internal/pycore_stackref.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h
index 9eba92d..1a68e0e 100644
--- a/Include/internal/pycore_stackref.h
+++ b/Include/internal/pycore_stackref.h
@@ -592,7 +592,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
// Note: this is a macro because MSVC (Windows) has trouble inlining it.
-#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_REFCNT)) == ((b).bits & (~Py_TAG_REFCNT)))
+#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS)))
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
@@ -640,6 +640,28 @@ PyStackRef_FunctionCheck(_PyStackRef stackref)
return PyFunction_Check(PyStackRef_AsPyObjectBorrow(stackref));
}
+static inline void
+_PyThreadState_PushCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
+{
+#ifdef Py_GIL_DISABLED
+ _PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
+ ref->next = tstate_impl->c_stack_refs;
+ tstate_impl->c_stack_refs = ref;
+#endif
+ ref->ref = PyStackRef_NULL;
+}
+
+static inline void
+_PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
+{
+#ifdef Py_GIL_DISABLED
+ _PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
+ assert(tstate_impl->c_stack_refs == ref);
+ tstate_impl->c_stack_refs = ref->next;
+#endif
+ PyStackRef_XCLOSE(ref->ref);
+}
+
#ifdef Py_GIL_DISABLED
static inline int
@@ -656,6 +678,17 @@ _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
return 0;
}
+static inline int
+_Py_TryXGetStackRef(PyObject **src, _PyStackRef *out)
+{
+ PyObject *op = _Py_atomic_load_ptr_relaxed(src);
+ if (op == NULL) {
+ *out = PyStackRef_NULL;
+ return 1;
+ }
+ return _Py_TryIncrefCompareStackRef(src, op, out);
+}
+
#endif
// Like Py_VISIT but for _PyStackRef fields