@@ -1639,6 +1639,29 @@ raise_exception(PyObject *self, PyObject *args)
16391639 return NULL ;
16401640}
16411641
1642+ static PyObject *
1643+ test_set_exc_info (PyObject * self , PyObject * args )
1644+ {
1645+ PyObject * orig_exc ;
1646+ PyObject * new_type , * new_value , * new_tb ;
1647+ PyObject * type , * value , * tb ;
1648+ if (!PyArg_ParseTuple (args , "OOO:test_set_exc_info" ,
1649+ & new_type , & new_value , & new_tb ))
1650+ return NULL ;
1651+
1652+ PyErr_GetExcInfo (& type , & value , & tb );
1653+
1654+ Py_INCREF (new_type );
1655+ Py_INCREF (new_value );
1656+ Py_INCREF (new_tb );
1657+ PyErr_SetExcInfo (new_type , new_value , new_tb );
1658+
1659+ orig_exc = PyTuple_Pack (3 , type ? type : Py_None , value ? value : Py_None , tb ? tb : Py_None );
1660+ Py_XDECREF (type );
1661+ Py_XDECREF (value );
1662+ Py_XDECREF (tb );
1663+ return orig_exc ;
1664+ }
16421665
16431666static int test_run_counter = 0 ;
16441667
@@ -2471,6 +2494,7 @@ static PyMethodDef TestMethods[] = {
24712494#endif
24722495 {"traceback_print" , traceback_print , METH_VARARGS },
24732496 {"exception_print" , exception_print , METH_VARARGS },
2497+ {"set_exc_info" , test_set_exc_info , METH_VARARGS },
24742498 {"argparsing" , argparsing , METH_VARARGS },
24752499 {"code_newempty" , code_newempty , METH_VARARGS },
24762500 {"make_exception_with_doc" , (PyCFunction )make_exception_with_doc ,
0 commit comments