cpython/Objects/frameobject.c

/* Frame object implementation */

#include "Python.h"
#include "pycore_ceval.h"         // _PyEval_SetOpcodeTrace()
#include "pycore_code.h"          // CO_FAST_LOCAL, etc.
#include "pycore_dict.h"          // _PyDict_LoadBuiltinsFromGlobals()
#include "pycore_function.h"      // _PyFunction_FromConstructor()
#include "pycore_moduleobject.h"  // _PyModule_GetDict()
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
#include "pycore_object.h"        // _PyObject_GC_UNTRACK()
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt, _PyOpcode_Caches


#include "frameobject.h"          // PyFrameObject
#include "pycore_frame.h"
#include "opcode.h"               // EXTENDED_ARG


#define OFF(x)


// Returns borrowed reference or NULL
static PyObject *
framelocalsproxy_getval(_PyInterpreterFrame *frame, PyCodeObject *co, int i)
{}

static int
framelocalsproxy_getkeyindex(PyFrameObject *frame, PyObject* key, bool read)
{}

static PyObject *
framelocalsproxy_getitem(PyObject *self, PyObject *key)
{}

static int
framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
{}

static int
framelocalsproxy_merge(PyObject* self, PyObject* other)
{}

static PyObject *
framelocalsproxy_keys(PyObject *self, void *Py_UNUSED(ignored))
{}

static void
framelocalsproxy_dealloc(PyObject *self)
{}

static PyObject *
framelocalsproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{}

static int
framelocalsproxy_tp_clear(PyObject *self)
{}

static int
framelocalsproxy_visit(PyObject *self, visitproc visit, void *arg)
{}

static PyObject *
framelocalsproxy_iter(PyObject *self)
{}

static PyObject *
framelocalsproxy_richcompare(PyObject *self, PyObject *other, int op)
{}

static PyObject *
framelocalsproxy_repr(PyObject *self)
{}

static PyObject*
framelocalsproxy_or(PyObject *self, PyObject *other)
{}

static PyObject*
framelocalsproxy_inplace_or(PyObject *self, PyObject *other)
{}

static PyObject*
framelocalsproxy_values(PyObject *self, void *Py_UNUSED(ignored))
{}

static PyObject *
framelocalsproxy_items(PyObject *self, void *Py_UNUSED(ignored))
{}

static Py_ssize_t
framelocalsproxy_length(PyObject *self)
{}

static int
framelocalsproxy_contains(PyObject *self, PyObject *key)
{}

static PyObject* framelocalsproxy___contains__(PyObject *self, PyObject *key)
{}

static PyObject*
framelocalsproxy_update(PyObject *self, PyObject *other)
{}

static PyObject*
framelocalsproxy_get(PyObject* self, PyObject *const *args, Py_ssize_t nargs)
{}

static PyObject*
framelocalsproxy_setdefault(PyObject* self, PyObject *const *args, Py_ssize_t nargs)
{}

static PyObject*
framelocalsproxy_pop(PyObject* self, PyObject *const *args, Py_ssize_t nargs)
{}

static PyObject*
framelocalsproxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject*
framelocalsproxy_reversed(PyObject *self, void *Py_UNUSED(ignored))
{}

static PyNumberMethods framelocalsproxy_as_number =;

static PySequenceMethods framelocalsproxy_as_sequence =;

static PyMappingMethods framelocalsproxy_as_mapping =;

static PyMethodDef framelocalsproxy_methods[] =;

PyTypeObject PyFrameLocalsProxy_Type =;

PyObject *
_PyFrameLocalsProxy_New(PyFrameObject *frame)
{}

static PyMemberDef frame_memberlist[] =;

static PyObject *
frame_getlocals(PyFrameObject *f, void *closure)
{}

int
PyFrame_GetLineNumber(PyFrameObject *f)
{}

static PyObject *
frame_getlineno(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_getlasti(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_getglobals(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_getbuiltins(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_getcode(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_getback(PyFrameObject *f, void *closure)
{}

static PyObject *
frame_gettrace_opcodes(PyFrameObject *f, void *closure)
{}

static int
frame_settrace_opcodes(PyFrameObject *f, PyObject* value, void *Py_UNUSED(ignored))
{}

/* Model the evaluation stack, to determine which jumps
 * are safe and how many values needs to be popped.
 * The stack is modelled by a 64 integer, treating any
 * stack that can't fit into 64 bits as "overflowed".
 */

Kind;

static int
compatible_kind(Kind from, Kind to) {}

#define BITS_PER_BLOCK

#define UNINITIALIZED
#define OVERFLOWED

#define MAX_STACK_ENTRIES
#define WILL_OVERFLOW

#define EMPTY_STACK

static inline int64_t
push_value(int64_t stack, Kind kind)
{}

static inline int64_t
pop_value(int64_t stack)
{}

#define MASK

static inline Kind
top_of_stack(int64_t stack)
{}

static inline Kind
peek(int64_t stack, int n)
{}

static Kind
stack_swap(int64_t stack, int n)
{}

static int64_t
pop_to_level(int64_t stack, int level) {}

#if 0
/* These functions are useful for debugging the stack marking code */

static char
tos_char(int64_t stack) {
    switch(top_of_stack(stack)) {
        case Iterator:
            return 'I';
        case Except:
            return 'E';
        case Object:
            return 'O';
        case Lasti:
            return 'L';
        case Null:
            return 'N';
    }
    return '?';
}

static void
print_stack(int64_t stack) {
    if (stack < 0) {
        if (stack == UNINITIALIZED) {
            printf("---");
        }
        else if (stack == OVERFLOWED) {
            printf("OVERFLOWED");
        }
        else {
            printf("??");
        }
        return;
    }
    while (stack) {
        printf("%c", tos_char(stack));
        stack = pop_value(stack);
    }
}

static void
print_stacks(int64_t *stacks, int n) {
    for (int i = 0; i < n; i++) {
        printf("%d: ", i);
        print_stack(stacks[i]);
        printf("\n");
    }
}

#endif

static int64_t *
mark_stacks(PyCodeObject *code_obj, int len)
{}

static int
compatible_stack(int64_t from_stack, int64_t to_stack)
{}

static const char *
explain_incompatible_stack(int64_t to_stack)
{}

static int *
marklines(PyCodeObject *code, int len)
{}

static int
first_line_not_before(int *lines, int len, int line)
{}

static bool frame_is_suspended(PyFrameObject *frame)
{}

/* Setter for f_lineno - you can set f_lineno from within a trace function in
 * order to jump to a given line of code, subject to some restrictions.  Most
 * lines are OK to jump to because they don't make any assumptions about the
 * state of the stack (obvious because you could remove the line and the code
 * would still work without any stack errors), but there are some constructs
 * that limit jumping:
 *
 *  o Any exception handlers.
 *  o 'for' and 'async for' loops can't be jumped into because the
 *    iterator needs to be on the stack.
 *  o Jumps cannot be made from within a trace function invoked with a
 *    'return' or 'exception' event since the eval loop has been exited at
 *    that time.
 */
static int
frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignored))
{}

static PyObject *
frame_gettrace(PyFrameObject *f, void *closure)
{}

static int
frame_settrace(PyFrameObject *f, PyObject* v, void *closure)
{}


static PyGetSetDef frame_getsetlist[] =;

static void
frame_dealloc(PyFrameObject *f)
{}

static int
frame_traverse(PyFrameObject *f, visitproc visit, void *arg)
{}

static int
frame_tp_clear(PyFrameObject *f)
{}

static PyObject *
frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
{}

PyDoc_STRVAR(clear__doc__,
"F.clear(): clear all references held by the frame");

static PyObject *
frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
{}

PyDoc_STRVAR(sizeof__doc__,
"F.__sizeof__() -> size of F in memory, in bytes");

static PyObject *
frame_repr(PyFrameObject *f)
{}

static PyMethodDef frame_methods[] =;

PyTypeObject PyFrame_Type =;

static void
init_frame(PyThreadState *tstate, _PyInterpreterFrame *frame,
           PyFunctionObject *func, PyObject *locals)
{}

PyFrameObject*
_PyFrame_New_NoTrack(PyCodeObject *code)
{}

/* Legacy API */
PyFrameObject*
PyFrame_New(PyThreadState *tstate, PyCodeObject *code,
            PyObject *globals, PyObject *locals)
{}

// Initialize frame free variables if needed
static void
frame_init_get_vars(_PyInterpreterFrame *frame)
{}


static int
frame_get_var(_PyInterpreterFrame *frame, PyCodeObject *co, int i,
              PyObject **pvalue)
{}


bool
_PyFrame_HasHiddenLocals(_PyInterpreterFrame *frame)
{}


PyObject *
_PyFrame_GetLocals(_PyInterpreterFrame *frame)
{}


PyObject *
PyFrame_GetVar(PyFrameObject *frame_obj, PyObject *name)
{}


PyObject *
PyFrame_GetVarString(PyFrameObject *frame, const char *name)
{}


int
PyFrame_FastToLocalsWithError(PyFrameObject *f)
{}

void
PyFrame_FastToLocals(PyFrameObject *f)
{}

void
PyFrame_LocalsToFast(PyFrameObject *f, int clear)
{}

int
_PyFrame_IsEntryFrame(PyFrameObject *frame)
{}

PyCodeObject *
PyFrame_GetCode(PyFrameObject *frame)
{}


PyFrameObject*
PyFrame_GetBack(PyFrameObject *frame)
{}

PyObject*
PyFrame_GetLocals(PyFrameObject *frame)
{}

PyObject*
PyFrame_GetGlobals(PyFrameObject *frame)
{}

PyObject*
PyFrame_GetBuiltins(PyFrameObject *frame)
{}

int
PyFrame_GetLasti(PyFrameObject *frame)
{}

PyObject *
PyFrame_GetGenerator(PyFrameObject *frame)
{}