#ifndef Py_INTERNAL_STACKREF_H
#define Py_INTERNAL_STACKREF_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_object_deferred.h"
#include <stddef.h>
#include <stdbool.h>
_PyStackRef;
#define Py_TAG_DEFERRED …
#define Py_TAG_PTR …
#define Py_TAG_BITS …
#ifdef Py_GIL_DISABLED
static const _PyStackRef PyStackRef_NULL = { .bits = 0 | Py_TAG_DEFERRED};
#else
static const _PyStackRef PyStackRef_NULL = …;
#endif
#define PyStackRef_IsNull(stackref) …
#ifdef Py_GIL_DISABLED
#define PyStackRef_True …
#else
#define PyStackRef_True …
#endif
#ifdef Py_GIL_DISABLED
#define PyStackRef_False …
#else
#define PyStackRef_False …
#endif
#ifdef Py_GIL_DISABLED
#define PyStackRef_None …
#else
#define PyStackRef_None …
#endif
#define PyStackRef_Is(a, b) …
#define PyStackRef_IsDeferred(ref) …
#ifdef Py_GIL_DISABLED
static inline PyObject *
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
{
PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
return cleared;
}
#else
#define PyStackRef_AsPyObjectBorrow(stackref) …
#endif
#ifdef Py_GIL_DISABLED
static inline PyObject *
PyStackRef_AsPyObjectSteal(_PyStackRef stackref)
{
if (!PyStackRef_IsNull(stackref) && PyStackRef_IsDeferred(stackref)) {
return Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref));
}
return PyStackRef_AsPyObjectBorrow(stackref);
}
#else
#define PyStackRef_AsPyObjectSteal(stackref) …
#endif
#define PyStackRef_AsPyObjectNew(stackref) …
#define PyStackRef_TYPE(stackref) …
#ifdef Py_GIL_DISABLED
static inline _PyStackRef
_PyStackRef_FromPyObjectSteal(PyObject *obj)
{
assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
int tag = (obj == NULL || _Py_IsImmortal(obj)) ? (Py_TAG_DEFERRED) : Py_TAG_PTR;
return ((_PyStackRef){.bits = ((uintptr_t)(obj)) | tag});
}
#define PyStackRef_FromPyObjectSteal …
#else
#define PyStackRef_FromPyObjectSteal(obj) …
#endif
#ifdef Py_GIL_DISABLED
static inline _PyStackRef
PyStackRef_FromPyObjectNew(PyObject *obj)
{
assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
assert(obj != NULL);
if (_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj)) {
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED };
}
else {
return (_PyStackRef){ .bits = (uintptr_t)(Py_NewRef(obj)) | Py_TAG_PTR };
}
}
#define PyStackRef_FromPyObjectNew …
#else
#define PyStackRef_FromPyObjectNew(obj) …
#endif
#ifdef Py_GIL_DISABLED
static inline _PyStackRef
PyStackRef_FromPyObjectImmortal(PyObject *obj)
{
assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
assert(obj != NULL);
assert(_Py_IsImmortal(obj));
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED };
}
#define PyStackRef_FromPyObjectImmortal …
#else
#define PyStackRef_FromPyObjectImmortal(obj) …
#endif
#define PyStackRef_CLEAR(op) …
#ifdef Py_GIL_DISABLED
#define PyStackRef_CLOSE …
#else
#define PyStackRef_CLOSE(stackref) …
#endif
#define PyStackRef_XCLOSE(stackref) …
#ifdef Py_GIL_DISABLED
static inline _PyStackRef
PyStackRef_DUP(_PyStackRef stackref)
{
if (PyStackRef_IsDeferred(stackref)) {
assert(PyStackRef_IsNull(stackref) ||
_Py_IsImmortal(PyStackRef_AsPyObjectBorrow(stackref)) ||
_PyObject_HasDeferredRefcount(PyStackRef_AsPyObjectBorrow(stackref)));
return stackref;
}
Py_INCREF(PyStackRef_AsPyObjectBorrow(stackref));
return stackref;
}
#else
#define PyStackRef_DUP(stackref) …
#endif
static inline void
_PyObjectStack_FromStackRefStack(PyObject **dst, const _PyStackRef *src, size_t length)
{ … }
static inline bool
PyStackRef_GenCheck(_PyStackRef stackref)
{ … }
static inline bool
PyStackRef_BoolCheck(_PyStackRef stackref)
{ … }
static inline bool
PyStackRef_LongCheck(_PyStackRef stackref)
{ … }
static inline bool
PyStackRef_ExceptionInstanceCheck(_PyStackRef stackref)
{ … }
static inline bool
PyStackRef_FunctionCheck(_PyStackRef stackref)
{ … }
#ifdef __cplusplus
}
#endif
#endif