Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52fbcf6

Browse files
authored
GH-107724: Fix the signature ofPY_THROW callback functions. (GH-107725)
1 parent2fb484e commit52fbcf6

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

‎Include/internal/pycore_instruments.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ extern int
9090
_Py_call_instrumentation_2args(PyThreadState*tstate,intevent,
9191
_PyInterpreterFrame*frame,_Py_CODEUNIT*instr,PyObject*arg0,PyObject*arg1);
9292

93-
externvoid
94-
_Py_call_instrumentation_exc0(PyThreadState*tstate,intevent,
95-
_PyInterpreterFrame*frame,_Py_CODEUNIT*instr);
96-
9793
externvoid
9894
_Py_call_instrumentation_exc2(PyThreadState*tstate,intevent,
9995
_PyInterpreterFrame*frame,_Py_CODEUNIT*instr,PyObject*arg0,PyObject*arg1);

‎Lib/test/test_monitoring.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ class ExceptionHandledRecorder(ExceptionRecorder):
743743
def__call__(self,code,offset,exc):
744744
self.events.append(("handled",type(exc)))
745745

746+
classThrowRecorder(ExceptionRecorder):
747+
748+
event_type=E.PY_THROW
749+
750+
def__call__(self,code,offset,exc):
751+
self.events.append(("throw",type(exc)))
752+
746753
classExceptionMonitoringTest(CheckEvents):
747754

748755

@@ -888,6 +895,31 @@ async def async_loop():
888895
func,
889896
recorders=self.exception_recorders)
890897

898+
deftest_throw(self):
899+
900+
defgen():
901+
yield1
902+
yield2
903+
904+
deffunc():
905+
try:
906+
g=gen()
907+
next(g)
908+
g.throw(IndexError)
909+
exceptIndexError:
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+
891923
classLineRecorder:
892924

893925
event_type=E.LINE
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

‎Python/ceval.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ monitor_throw(PyThreadState *tstate,
20392039
if (no_tools_for_event(tstate,frame,PY_MONITORING_EVENT_PY_THROW)) {
20402040
return;
20412041
}
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);
20432043
}
20442044

20452045
void

‎Python/instrumentation.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,6 @@ call_instrumentation_vector_protected(
10811081
assert(_PyErr_Occurred(tstate));
10821082
}
10831083

1084-
void
1085-
_Py_call_instrumentation_exc0(
1086-
PyThreadState*tstate,intevent,
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-
10941084
void
10951085
_Py_call_instrumentation_exc2(
10961086
PyThreadState*tstate,intevent,

‎Python/legacy_tracing.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ sys_trace_func2(
163163
}
164164

165165
staticPyObject*
166-
sys_trace_unwind(
166+
sys_trace_func3(
167167
_PyLegacyEventHandler*self,PyObject*const*args,
168168
size_tnargsf,PyObject*kwnames
169169
) {
@@ -445,7 +445,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
445445
return-1;
446446
}
447447
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
448-
(vectorcallfunc)sys_trace_func2,PyTrace_CALL,
448+
(vectorcallfunc)sys_trace_func3,PyTrace_CALL,
449449
PY_MONITORING_EVENT_PY_THROW,-1)) {
450450
return-1;
451451
}
@@ -470,7 +470,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
470470
return-1;
471471
}
472472
if (set_callbacks(PY_MONITORING_SYS_TRACE_ID,
473-
(vectorcallfunc)sys_trace_unwind,PyTrace_RETURN,
473+
(vectorcallfunc)sys_trace_func3,PyTrace_RETURN,
474474
PY_MONITORING_EVENT_PY_UNWIND,-1)) {
475475
return-1;
476476
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp