@@ -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
@@ -2531,6 +2564,7 @@ test_threadstate_set_stack_protection(PyObject *self, PyObject *Py_UNUSED(args))
25312564
25322565static PyMethodDef module_functions [] = {
25332566 {"get_configs" , get_configs , METH_NOARGS },
2567+ {"get_eval_frame_stats" , get_eval_frame_stats , METH_NOARGS , NULL },
25342568 {"get_recursion_depth" , get_recursion_depth , METH_NOARGS },
25352569 {"get_c_recursion_remaining" , get_c_recursion_remaining , METH_NOARGS },
25362570 {"get_stack_pointer" , get_stack_pointer , METH_NOARGS },
@@ -2547,6 +2581,7 @@ static PyMethodDef module_functions[] = {
25472581 {"EncodeLocaleEx" , encode_locale_ex , METH_VARARGS },
25482582 {"DecodeLocaleEx" , decode_locale_ex , METH_VARARGS },
25492583 {"set_eval_frame_default" , set_eval_frame_default , METH_NOARGS , NULL },
2584+ {"set_eval_frame_interp" , set_eval_frame_interp , METH_NOARGS , NULL },
25502585 {"set_eval_frame_record" , set_eval_frame_record , METH_O , NULL },
25512586 _TESTINTERNALCAPI_COMPILER_CLEANDOC_METHODDEF
25522587 _TESTINTERNALCAPI_NEW_INSTRUCTION_SEQUENCE_METHODDEF
0 commit comments