예제 #1
0
static PyObject *Nuitka_Frame_clear( PyFrameObject *frame )
{
    if ( frame->f_executing )
    {
        PyErr_Format(
            PyExc_RuntimeError,
            "cannot clear an executing frame"
        );

        return NULL;
    }

#if PYTHON_VERSION >= 340
    // For frames that are closed, we also need to close the generator.
    if ( frame->f_gen != NULL )
    {
        Py_INCREF( frame );

        assert( Nuitka_Generator_Check( frame->f_gen ) );

        Nuitka_GeneratorObject *generator = (Nuitka_GeneratorObject *)frame->f_gen;
        frame->f_gen = NULL;

        PyObject *close_result = Nuitka_Generator_close(
            generator,
            NULL
        );

        if (unlikely( close_result == NULL ))
        {
            PyErr_WriteUnraisable( (PyObject *)frame->f_gen );
        }
        else
        {
            Py_DECREF( close_result );
        }

        Py_DECREF( frame );
    }
#endif

    Nuitka_Frame_tp_clear( frame );

    Py_RETURN_NONE;
}
예제 #2
0
static void Nuitka_Frame_tp_dealloc(struct Nuitka_FrameObject *nuitka_frame) {
#ifndef __NUITKA_NO_ASSERT__
    // Save the current exception, if any, we must to not corrupt it.
    PyObject *save_exception_type, *save_exception_value;
    PyTracebackObject *save_exception_tb;
    FETCH_ERROR_OCCURRED(&save_exception_type, &save_exception_value, &save_exception_tb);
    RESTORE_ERROR_OCCURRED(save_exception_type, save_exception_value, save_exception_tb);
#endif

    Nuitka_GC_UnTrack(nuitka_frame);

    PyFrameObject *frame = &nuitka_frame->m_frame;

    Py_XDECREF(frame->f_back);
    Py_DECREF(frame->f_builtins);
    Py_DECREF(frame->f_globals);
    Py_XDECREF(frame->f_locals);

#if PYTHON_VERSION < 370
    Py_XDECREF(frame->f_exc_type);
    Py_XDECREF(frame->f_exc_value);
    Py_XDECREF(frame->f_exc_traceback);
#endif

    Nuitka_Frame_tp_clear(nuitka_frame);

    releaseToFreeList(free_list_frames, nuitka_frame, MAX_FRAME_FREE_LIST_COUNT);

#ifndef __NUITKA_NO_ASSERT__
    PyThreadState *tstate = PyThreadState_GET();

    assert(tstate->curexc_type == save_exception_type);
    assert(tstate->curexc_value == save_exception_value);
    assert((PyTracebackObject *)tstate->curexc_traceback == save_exception_tb);
#endif
}
예제 #3
0
static PyObject *Nuitka_Frame_clear(struct Nuitka_FrameObject *frame) {
    if (frame->m_frame.f_executing) {
        PyErr_Format(PyExc_RuntimeError, "cannot clear an executing frame");

        return NULL;
    }

#if PYTHON_VERSION >= 340
    // For frames that are closed, we also need to close the generator.
    if (frame->m_frame.f_gen != NULL) {
        Py_INCREF(frame);

        CHECK_OBJECT(frame->m_frame.f_gen);
        PyObject *f_gen = frame->m_frame.f_gen;

        PyObject *close_result;
        if (Nuitka_Generator_Check(frame->m_frame.f_gen)) {
            struct Nuitka_GeneratorObject *generator = (struct Nuitka_GeneratorObject *)frame->m_frame.f_gen;
            frame->m_frame.f_gen = NULL;

            close_result = Nuitka_Generator_close(generator, NULL);
        }
#if PYTHON_VERSION >= 350
        else if (Nuitka_Coroutine_Check(frame->m_frame.f_gen)) {
            struct Nuitka_CoroutineObject *coroutine = (struct Nuitka_CoroutineObject *)frame->m_frame.f_gen;
            frame->m_frame.f_gen = NULL;

            close_result = Nuitka_Coroutine_close(coroutine, NULL);
        }
#endif
#if PYTHON_VERSION >= 360
        else if (Nuitka_Asyncgen_Check(frame->m_frame.f_gen)) {
            struct Nuitka_AsyncgenObject *asyncgen = (struct Nuitka_AsyncgenObject *)frame->m_frame.f_gen;
            frame->m_frame.f_gen = NULL;

            close_result = Nuitka_Asyncgen_close(asyncgen, NULL);
        }
#endif
        else {
            // Compiled frames should only have our types.
            assert(false);

            frame->m_frame.f_gen = NULL;

            close_result = Py_None;
            Py_INCREF(close_result);
        }

        if (unlikely(close_result == NULL)) {
            PyErr_WriteUnraisable(f_gen);
        } else {
            Py_DECREF(close_result);
        }

        Py_DECREF(frame);
    }
#endif

    Nuitka_Frame_tp_clear(frame);

    Py_RETURN_NONE;
}
예제 #4
0
void Nuitka_Frame_ReleaseLocals(struct Nuitka_FrameObject *frame) { Nuitka_Frame_tp_clear(frame); }