static PyObject *_inspect_getgeneratorstate_replacement( PyObject *self, PyObject *args, PyObject *kwds ) { PyObject *object; if ( !PyArg_ParseTupleAndKeywords( args, kwds, "O:getgeneratorstate", kwlist, &object, NULL )) { return NULL; } if ( Nuitka_Generator_Check( object ) ) { Nuitka_GeneratorObject *generator = (Nuitka_GeneratorObject *)object; if ( generator->m_running ) { return PyObject_GetAttrString( module_inspect, "GEN_RUNNING" ); } else if ( generator->m_status == status_Finished ) { return PyObject_GetAttrString( module_inspect, "GEN_CLOSED" ); } else if ( generator->m_status == status_Unused ) { return PyObject_GetAttrString( module_inspect, "GEN_CREATED" ); } else { return PyObject_GetAttrString( module_inspect, "GEN_SUSPENDED" ); } } else { return old_getgeneratorstate->ob_type->tp_call( old_getgeneratorstate, args, kwds ); } }
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; }
static char const *GET_CALLABLE_DESC( PyObject *object ) { if ( Nuitka_Function_Check( object ) || Nuitka_Generator_Check( object ) || PyMethod_Check( object ) || PyFunction_Check( object ) || PyCFunction_Check( object ) ) { return "()"; } #if PYTHON_VERSION < 300 else if ( PyClass_Check( object ) ) { return " constructor"; } else if ( PyInstance_Check( object )) { return " instance"; } #endif else { return " object"; } }
static char const *GET_CALLABLE_NAME( PyObject *object ) { if ( Nuitka_Function_Check( object ) ) { return Nuitka_String_AsString( Nuitka_Function_GetName( object ) ); } else if ( Nuitka_Generator_Check( object ) ) { return Nuitka_String_AsString( Nuitka_Generator_GetName( object ) ); } else if ( PyMethod_Check( object ) ) { return PyEval_GetFuncName( PyMethod_GET_FUNCTION( object ) ); } else if ( PyFunction_Check( object ) ) { return Nuitka_String_AsString( ((PyFunctionObject*)object)->func_name ); } #if PYTHON_VERSION < 300 else if ( PyInstance_Check( object ) ) { return Nuitka_String_AsString( ((PyInstanceObject*)object)->in_class->cl_name ); } else if ( PyClass_Check( object ) ) { return Nuitka_String_AsString( ((PyClassObject*)object)->cl_name ); } #endif else if ( PyCFunction_Check( object ) ) { return ((PyCFunctionObject*)object)->m_ml->ml_name; } else { return Py_TYPE( object )->tp_name; } }
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; }