@@ -693,6 +693,39 @@ set_eval_frame_record(PyObject *self, PyObject *list)
693693 Py_RETURN_NONE ;
694694}
695695
696+ // Defined in interpreter.c
697+ extern PyObject *
698+ Test_EvalFrame (PyThreadState * tstate , _PyInterpreterFrame * frame , int throwflag );
699+ extern int Test_EvalFrame_Resumes , Test_EvalFrame_Loads ;
700+
701+ static PyObject *
702+ get_eval_frame_stats (PyObject * self , PyObject * Py_UNUSED (args ))
703+ {
704+ PyObject * res = PyDict_New ();
705+ if (res == NULL ) {
706+ return NULL ;
707+ }
708+ PyObject * resumes = PyLong_FromLong (Test_EvalFrame_Resumes );
709+ if (resumes == NULL || PyDict_SetItemString (res , "resumes" , resumes ) < 0 ) {
710+ Py_XDECREF (resumes );
711+ return NULL ;
712+ }
713+ PyObject * loads = PyLong_FromLong (Test_EvalFrame_Loads );
714+ if (loads == NULL || PyDict_SetItemString (res , "loads" , loads ) < 0 ) {
715+ Py_XDECREF (loads );
716+ return NULL ;
717+ }
718+ Test_EvalFrame_Resumes = Test_EvalFrame_Loads = 0 ;
719+ return res ;
720+ }
721+
722+ static PyObject *
723+ set_eval_frame_interp (PyObject * self , PyObject * Py_UNUSED (args ))
724+ {
725+ _PyInterpreterState_SetEvalFrameFunc (_PyInterpreterState_GET (), Test_EvalFrame );
726+ Py_RETURN_NONE ;
727+ }
728+
696729/*[clinic input]
697730
698731_testinternalcapi.compiler_cleandoc -> object
@@ -2507,6 +2540,7 @@ test_threadstate_set_stack_protection(PyObject *self, PyObject *Py_UNUSED(args))
25072540
25082541static PyMethodDef module_functions [] = {
25092542 {"get_configs" , get_configs , METH_NOARGS },
2543+ {"get_eval_frame_stats" , get_eval_frame_stats , METH_NOARGS , NULL },
25102544 {"get_recursion_depth" , get_recursion_depth , METH_NOARGS },
25112545 {"get_c_recursion_remaining" , get_c_recursion_remaining , METH_NOARGS },
25122546 {"get_stack_pointer" , get_stack_pointer , METH_NOARGS },
@@ -2523,6 +2557,7 @@ static PyMethodDef module_functions[] = {
25232557 {"EncodeLocaleEx" , encode_locale_ex , METH_VARARGS },
25242558 {"DecodeLocaleEx" , decode_locale_ex , METH_VARARGS },
25252559 {"set_eval_frame_default" , set_eval_frame_default , METH_NOARGS , NULL },
2560+ {"set_eval_frame_interp" , set_eval_frame_interp , METH_NOARGS , NULL },
25262561 {"set_eval_frame_record" , set_eval_frame_record , METH_O , NULL },
25272562 _TESTINTERNALCAPI_COMPILER_CLEANDOC_METHODDEF
25282563 _TESTINTERNALCAPI_NEW_INSTRUCTION_SEQUENCE_METHODDEF
0 commit comments