static PyFrameObject *MAKE_FRAME( PyCodeObject *code, PyObject *module, bool is_module ) { PyTraceBack_Type.tp_dealloc = (destructor)tb_dealloc; assertCodeObject( code ); PyObject *globals = ((PyModuleObject *)module)->md_dict; assert( PyDict_Check( globals ) ); Py_ssize_t ncells = PyTuple_GET_SIZE( code->co_cellvars ); Py_ssize_t nfrees = PyTuple_GET_SIZE( code->co_freevars ); Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; Nuitka_FrameObject *result = PyObject_GC_NewVar( Nuitka_FrameObject, &Nuitka_Frame_Type, extras ); if (unlikely( result == NULL )) { return NULL; } PyFrameObject *frame = &result->m_frame; frame->f_code = code; extras = code->co_nlocals + ncells + nfrees; frame->f_valuestack = frame->f_localsplus + extras; for ( Py_ssize_t i = 0; i < extras; i++ ) { frame->f_localsplus[i] = NULL; } frame->f_locals = NULL; frame->f_trace = INCREASE_REFCOUNT( Py_None ); frame->f_exc_type = NULL; frame->f_exc_value = NULL; frame->f_exc_traceback = NULL; frame->f_stacktop = frame->f_valuestack; frame->f_builtins = INCREASE_REFCOUNT( (PyObject *)dict_builtin ); frame->f_back = NULL; frame->f_globals = INCREASE_REFCOUNT( globals ); if (likely( (code->co_flags & CO_OPTIMIZED ) == CO_OPTIMIZED )) { frame->f_locals = NULL; } else if (is_module) { frame->f_locals = INCREASE_REFCOUNT( globals ); } else { frame->f_locals = PyDict_New(); if (unlikely( frame->f_locals == NULL )) { Py_DECREF( result ); return NULL; } PyDict_SetItem( frame->f_locals, const_str_plain___module__, MODULE_NAME( module ) ); } #if PYTHON_VERSION < 340 frame->f_tstate = PyThreadState_GET(); #endif frame->f_lasti = -1; frame->f_lineno = code->co_firstlineno; frame->f_iblock = 0; #if PYTHON_VERSION >= 340 frame->f_gen = NULL; frame->f_executing = 0; #endif Nuitka_GC_Track( result ); return (PyFrameObject *)result; }
static struct Nuitka_FrameObject *MAKE_FRAME(PyCodeObject *code, PyObject *module, bool is_module, Py_ssize_t locals_size) { assertCodeObject(code); PyObject *globals = ((PyModuleObject *)module)->md_dict; assert(PyDict_Check(globals)); struct Nuitka_FrameObject *result; // Macro to assign result memory from GC or free list. allocateFromFreeList(free_list_frames, struct Nuitka_FrameObject, Nuitka_Frame_Type, locals_size); result->m_type_description = NULL; PyFrameObject *frame = &result->m_frame; frame->f_code = code; frame->f_trace = Py_None; #if PYTHON_VERSION < 370 frame->f_exc_type = NULL; frame->f_exc_value = NULL; frame->f_exc_traceback = NULL; #else frame->f_trace_lines = 0; frame->f_trace_opcodes = 0; #endif Py_INCREF(dict_builtin); frame->f_builtins = (PyObject *)dict_builtin; frame->f_back = NULL; Py_INCREF(globals); frame->f_globals = globals; if (likely((code->co_flags & CO_OPTIMIZED) == CO_OPTIMIZED)) { frame->f_locals = NULL; } else if (is_module) { Py_INCREF(globals); frame->f_locals = globals; } else { frame->f_locals = PyDict_New(); if (unlikely(frame->f_locals == NULL)) { Py_DECREF(result); return NULL; } PyDict_SetItem(frame->f_locals, const_str_plain___module__, MODULE_NAME(module)); } #if PYTHON_VERSION < 340 frame->f_tstate = PyThreadState_GET(); #endif frame->f_lasti = -1; frame->f_lineno = code->co_firstlineno; frame->f_iblock = 0; #if PYTHON_VERSION >= 340 frame->f_gen = NULL; frame->f_executing = 0; #endif Nuitka_GC_Track(result); return result; }