@@ -6345,6 +6345,33 @@ settrace_to_record(PyObject *self, PyObject *list)
63456345 Py_RETURN_NONE ;
63466346}
63476347
6348+ static int
6349+ error_func (PyObject * obj , PyFrameObject * f , int what , PyObject * arg )
6350+ {
6351+ assert (PyList_Check (obj ));
6352+ /* Only raise if list is empty, otherwise append None
6353+ * This ensures that we only raise once */
6354+ if (PyList_GET_SIZE (obj )) {
6355+ return 0 ;
6356+ }
6357+ if (PyList_Append (obj , Py_None )) {
6358+ return -1 ;
6359+ }
6360+ PyErr_SetString (PyExc_Exception , "an exception" );
6361+ return -1 ;
6362+ }
6363+
6364+ static PyObject *
6365+ settrace_to_error (PyObject * self , PyObject * list )
6366+ {
6367+ if (!PyList_Check (list )) {
6368+ PyErr_SetString (PyExc_TypeError , "argument must be a list" );
6369+ return NULL ;
6370+ }
6371+ PyEval_SetTrace (error_func , list );
6372+ Py_RETURN_NONE ;
6373+ }
6374+
63486375static PyObject * negative_dictoffset (PyObject * , PyObject * );
63496376
63506377static PyObject *
@@ -6694,6 +6721,7 @@ static PyMethodDef TestMethods[] = {
66946721 {"eval_get_func_desc" , eval_get_func_desc , METH_O , NULL },
66956722 {"get_feature_macros" , get_feature_macros , METH_NOARGS , NULL },
66966723 {"test_code_api" , test_code_api , METH_NOARGS , NULL },
6724+ {"settrace_to_error" , settrace_to_error , METH_O , NULL },
66976725 {"settrace_to_record" , settrace_to_record , METH_O , NULL },
66986726 {"function_get_code" , function_get_code , METH_O , NULL },
66996727 {"function_get_globals" , function_get_globals , METH_O , NULL },
0 commit comments