1515#include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
1616#include "pycore_bitutils.h" // _Py_bswap32()
1717#include "pycore_fileutils.h" // _Py_normpath
18+ #include "pycore_frame.h" // _PyInterpreterFrame
1819#include "pycore_gc.h" // PyGC_Head
1920#include "pycore_hashtable.h" // _Py_hashtable_new()
2021#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
2122#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
2223#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
2324#include "pycore_pyerrors.h" // _Py_UTF8_Edit_Cost()
2425#include "pycore_pystate.h" // _PyThreadState_GET()
25- #include "osdefs.h" // MAXPATHLEN
26+ #include "osdefs.h" // MAXPATHLEN
2627
2728
2829static PyObject *
@@ -491,6 +492,38 @@ decode_locale_ex(PyObject *self, PyObject *args)
491492 return res ;
492493}
493494
495+ static PyObject * record_list = NULL ;
496+
497+ static PyObject *
498+ set_eval_frame_default (PyObject * self , PyObject * Py_UNUSED (args ))
499+ {
500+ _PyInterpreterState_SetEvalFrameFunc (PyInterpreterState_Get (), _PyEval_EvalFrameDefault );
501+ Py_CLEAR (record_list );
502+ Py_RETURN_NONE ;
503+ }
504+
505+ static PyObject *
506+ record_eval (PyThreadState * tstate , struct _PyInterpreterFrame * f , int exc )
507+ {
508+ PyList_Append (record_list , f -> f_func -> func_name );
509+ return _PyEval_EvalFrameDefault (tstate , f , exc );
510+ }
511+
512+
513+ static PyObject *
514+ set_eval_frame_record (PyObject * self , PyObject * list )
515+ {
516+ if (!PyList_Check (list )) {
517+ PyErr_SetString (PyExc_TypeError , "argument must be a list" );
518+ return NULL ;
519+ }
520+ Py_CLEAR (record_list );
521+ Py_INCREF (list );
522+ record_list = list ;
523+ _PyInterpreterState_SetEvalFrameFunc (PyInterpreterState_Get (), record_eval );
524+ Py_RETURN_NONE ;
525+ }
526+
494527
495528static PyMethodDef TestMethods [] = {
496529 {"get_configs" , get_configs , METH_NOARGS },
@@ -508,6 +541,8 @@ static PyMethodDef TestMethods[] = {
508541 {"get_getpath_codeobject" , get_getpath_codeobject , METH_NOARGS , NULL },
509542 {"EncodeLocaleEx" , encode_locale_ex , METH_VARARGS },
510543 {"DecodeLocaleEx" , decode_locale_ex , METH_VARARGS },
544+ {"set_eval_frame_default" , set_eval_frame_default , METH_NOARGS , NULL },
545+ {"set_eval_frame_record" , set_eval_frame_record , METH_O , NULL },
511546 {NULL , NULL } /* sentinel */
512547};
513548
0 commit comments