1#ifndef GREENLET_MSVC_COMPAT_HPP
2#define GREENLET_MSVC_COMPAT_HPP
27#include "greenlet_cpython_compat.hpp"
34#define _PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
38#if !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
42#define Py_TAG_BITS ((uintptr_t)1)
43#define Py_TAG_DEFERRED (1)
47static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
48#define PyStackRef_IsNull(stackref) ((stackref).bits == PyStackRef_NULL.bits)
50static inline PyObject *
51PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
53 PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
57static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
58 assert(!PyStackRef_IsNull(f->f_executable));
59 PyObject *executable = PyStackRef_AsPyObjectBorrow(f->f_executable);
60 assert(PyCode_Check(executable));
61 return (PyCodeObject *)executable;
65static inline _Py_CODEUNIT *
66_PyFrame_GetBytecode(_PyInterpreterFrame *f)
69 PyCodeObject *co = _PyFrame_GetCode(f);
70 _PyCodeArray *tlbc = _PyCode_GetTLBCArray(co);
71 assert(f->tlbc_index >= 0 && f->tlbc_index < tlbc->size);
72 return (_Py_CODEUNIT *)tlbc->entries[f->tlbc_index];
74 return _PyCode_CODE(_PyFrame_GetCode(f));
79_PyFrame_IsIncomplete(_PyInterpreterFrame *frame)
81 if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
84 return frame->owner != FRAME_OWNED_BY_GENERATOR &&
85 frame->instr_ptr < _PyFrame_GetBytecode(frame) +
86 _PyFrame_GetCode(frame)->_co_firsttraceable;