| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,10 +90,6 @@ extern int | |||
| 90 | 90 | _Py_call_instrumentation_2args(PyThreadState *tstate, int event, | |
| 91 | 91 | _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1); | |
| 92 | 92 | ||
| 93 | - extern void | ||
| 94 | - _Py_call_instrumentation_exc0(PyThreadState *tstate, int event, | ||
| 95 | - _PyInterpreterFrame *frame, _Py_CODEUNIT *instr); | ||
| 96 | - | ||
| 97 | 93 | extern void | |
| 98 | 94 | _Py_call_instrumentation_exc2(PyThreadState *tstate, int event, | |
| 99 | 95 | _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -743,6 +743,13 @@ class ExceptionHandledRecorder(ExceptionRecorder): | |||
| 743 | 743 | def __call__(self, code, offset, exc): | |
| 744 | 744 | self.events.append(("handled", type(exc))) | |
| 745 | 745 | ||
| 746 | + class ThrowRecorder(ExceptionRecorder): | ||
| 747 | + | ||
| 748 | + event_type = E.PY_THROW | ||
| 749 | + | ||
| 750 | + def __call__(self, code, offset, exc): | ||
| 751 | + self.events.append(("throw", type(exc))) | ||
| 752 | + | ||
| 746 | 753 | class ExceptionMonitoringTest(CheckEvents): | |
| 747 | 754 | ||
| 748 | 755 | ||
@@ -888,6 +895,31 @@ async def async_loop(): | |||
| 888 | 895 | func, | |
| 889 | 896 | recorders = self.exception_recorders) | |
| 890 | 897 | ||
| 898 | + def test_throw(self): | ||
| 899 | + | ||
| 900 | + def gen(): | ||
| 901 | + yield 1 | ||
| 902 | + yield 2 | ||
| 903 | + | ||
| 904 | + def func(): | ||
| 905 | + try: | ||
| 906 | + g = gen() | ||
| 907 | + next(g) | ||
| 908 | + g.throw(IndexError) | ||
| 909 | + except IndexError: | ||
| 910 | + pass | ||
| 911 | + | ||
| 912 | + self.check_balanced( | ||
| 913 | + func, | ||
| 914 | + recorders = self.exception_recorders) | ||
| 915 | + | ||
| 916 | + events = self.get_events( | ||
| 917 | + func, | ||
| 918 | + TEST_TOOL, | ||
| 919 | + self.exception_recorders + (ThrowRecorder,) | ||
| 920 | + ) | ||
| 921 | + self.assertEqual(events[0], ("throw", IndexError)) | ||
| 922 | + | ||
| 891 | 923 | class LineRecorder: | |
| 892 | 924 | ||
| 893 | 925 | event_type = E.LINE | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + In pre-release versions of 3.12, up to rc1, the sys.monitoring callback | ||
| 2 | + function for the ``PY_THROW`` event was missing the third, exception | ||
| 3 | + argument. That is now fixed. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2039,7 +2039,7 @@ monitor_throw(PyThreadState *tstate, | |||
| 2039 | 2039 | if (no_tools_for_event(tstate, frame, PY_MONITORING_EVENT_PY_THROW)) { | |
| 2040 | 2040 | return; | |
| 2041 | 2041 | } | |
| 2042 | - _Py_call_instrumentation_exc0(tstate, PY_MONITORING_EVENT_PY_THROW, frame, instr); | ||
| 2042 | + do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_PY_THROW); | ||
| 2043 | 2043 | } | |
| 2044 | 2044 | ||
| 2045 | 2045 | void | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1081,16 +1081,6 @@ call_instrumentation_vector_protected( | |||
| 1081 | 1081 | assert(_PyErr_Occurred(tstate)); | |
| 1082 | 1082 | } | |
| 1083 | 1083 | ||
| 1084 | - void | ||
| 1085 | - _Py_call_instrumentation_exc0( | ||
| 1086 | - PyThreadState *tstate, int event, | ||
| 1087 | - _PyInterpreterFrame *frame, _Py_CODEUNIT *instr) | ||
| 1088 | - { | ||
| 1089 | - assert(_PyErr_Occurred(tstate)); | ||
| 1090 | - PyObject *args[3] = { NULL, NULL, NULL }; | ||
| 1091 | - call_instrumentation_vector_protected(tstate, event, frame, instr, 2, args); | ||
| 1092 | - } | ||
| 1093 | - | ||
| 1094 | 1084 | void | |
| 1095 | 1085 | _Py_call_instrumentation_exc2( | |
| 1096 | 1086 | PyThreadState *tstate, int event, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,7 +163,7 @@ sys_trace_func2( | |||
| 163 | 163 | } | |
| 164 | 164 | ||
| 165 | 165 | static PyObject * | |
| 166 | - sys_trace_unwind( | ||
| 166 | + sys_trace_func3( | ||
| 167 | 167 | _PyLegacyEventHandler *self, PyObject *const *args, | |
| 168 | 168 | size_t nargsf, PyObject *kwnames | |
| 169 | 169 | ) { | |
@@ -445,7 +445,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg) | |||
| 445 | 445 | return -1; | |
| 446 | 446 | } | |
| 447 | 447 | if (set_callbacks(PY_MONITORING_SYS_TRACE_ID, | |
| 448 | - (vectorcallfunc)sys_trace_func2, PyTrace_CALL, | ||
| 448 | + (vectorcallfunc)sys_trace_func3, PyTrace_CALL, | ||
| 449 | 449 | PY_MONITORING_EVENT_PY_THROW, -1)) { | |
| 450 | 450 | return -1; | |
| 451 | 451 | } | |
@@ -470,7 +470,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg) | |||
| 470 | 470 | return -1; | |
| 471 | 471 | } | |
| 472 | 472 | if (set_callbacks(PY_MONITORING_SYS_TRACE_ID, | |
| 473 | - (vectorcallfunc)sys_trace_unwind, PyTrace_RETURN, | ||
| 473 | + (vectorcallfunc)sys_trace_func3, PyTrace_RETURN, | ||
| 474 | 474 | PY_MONITORING_EVENT_PY_UNWIND, -1)) { | |
| 475 | 475 | return -1; | |
| 476 | 476 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments