diff options
author | Carl Meyer <carl@oddbird.net> | 2023-03-08 00:10:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 00:10:58 (GMT) |
commit | 1e703a473343ed198c9a06a876b25d7d69d4bbd0 (patch) | |
tree | 0ca3e31d0953a8ec475a159e19b5570e104eeefa /Modules | |
parent | a33ca2ad1fcf857817cba505a788e15cf9d6ed0c (diff) | |
download | cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.zip cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.tar.gz cpython-1e703a473343ed198c9a06a876b25d7d69d4bbd0.tar.bz2 |
gh-102381: don't call watcher callback with dead object (#102382)
Co-authored-by: T. Wouters <thomas@python.org>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapi/watchers.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c index d9ace63..1284fdc 100644 --- a/Modules/_testcapi/watchers.c +++ b/Modules/_testcapi/watchers.c @@ -317,6 +317,13 @@ noop_code_event_handler(PyCodeEvent event, PyCodeObject *co) return 0; } +static int +error_code_event_handler(PyCodeEvent event, PyCodeObject *co) +{ + PyErr_SetString(PyExc_RuntimeError, "boom!"); + return -1; +} + static PyObject * add_code_watcher(PyObject *self, PyObject *which_watcher) { @@ -333,7 +340,11 @@ add_code_watcher(PyObject *self, PyObject *which_watcher) num_code_object_created_events[1] = 0; num_code_object_destroyed_events[1] = 0; } + else if (which_l == 2) { + watcher_id = PyCode_AddWatcher(error_code_event_handler); + } else { + PyErr_Format(PyExc_ValueError, "invalid watcher %d", which_l); return NULL; } if (watcher_id < 0) { @@ -672,7 +683,7 @@ _PyTestCapi_Init_Watchers(PyObject *mod) PyFunction_EVENT_##event)) { \ return -1; \ } - FOREACH_FUNC_EVENT(ADD_EVENT); + PY_FOREACH_FUNC_EVENT(ADD_EVENT); #undef ADD_EVENT return 0; |