Skip to content

Commit a160b6a

Browse files
committed
Modules/_testcapi/watchers.c
1 parent 3064f2d commit a160b6a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Modules/_testcapi/watchers.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,15 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
389389
watcher_ids[i] = watcher_id;
390390
num_watchers++;
391391
}
392-
PyObject *type, *value, *traceback;
393-
PyErr_Fetch(&type, &value, &traceback);
392+
PyObject *exc = PyErr_GetRaisedException();
394393
for (int i = 0; i < num_watchers; i++) {
395394
if (PyCode_ClearWatcher(watcher_ids[i]) < 0) {
396395
PyErr_WriteUnraisable(Py_None);
397396
break;
398397
}
399398
}
400-
if (type) {
401-
PyErr_Restore(type, value, traceback);
399+
if (exc) {
400+
PyErr_SetRaisedException(exc);
402401
return NULL;
403402
}
404403
else if (PyErr_Occurred()) {
@@ -578,16 +577,15 @@ allocate_too_many_func_watchers(PyObject *self, PyObject *args)
578577
watcher_ids[i] = watcher_id;
579578
num_watchers++;
580579
}
581-
PyObject *type, *value, *traceback;
582-
PyErr_Fetch(&type, &value, &traceback);
580+
PyObject *exc = PyErr_GetRaisedException();
583581
for (int i = 0; i < num_watchers; i++) {
584582
if (PyFunction_ClearWatcher(watcher_ids[i]) < 0) {
585583
PyErr_WriteUnraisable(Py_None);
586584
break;
587585
}
588586
}
589-
if (type) {
590-
PyErr_Restore(type, value, traceback);
587+
if (exc) {
588+
PyErr_SetRaisedException(exc);
591589
return NULL;
592590
}
593591
else if (PyErr_Occurred()) {

0 commit comments

Comments
 (0)