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 /Doc/c-api/code.rst | |
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 'Doc/c-api/code.rst')
-rw-r--r-- | Doc/c-api/code.rst | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst index 062ef3a..a99de99 100644 --- a/Doc/c-api/code.rst +++ b/Doc/c-api/code.rst @@ -172,6 +172,11 @@ bound into a function. before the destruction of *co* takes place, so the prior state of *co* can be inspected. + If *event* is ``PY_CODE_EVENT_DESTROY``, taking a reference in the callback + to the about-to-be-destroyed code object will resurrect it and prevent it + from being freed at this time. When the resurrected object is destroyed + later, any watcher callbacks active at that time will be called again. + Users of this API should not rely on internal runtime implementation details. Such details may include, but are not limited to, the exact order and timing of creation and destruction of code objects. While @@ -179,9 +184,15 @@ bound into a function. (including whether a callback is invoked or not), it does not change the semantics of the Python code being executed. - If the callback returns with an exception set, it must return ``-1``; this - exception will be printed as an unraisable exception using - :c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``. + If the callback sets an exception, it must return ``-1``; this exception will + be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`. + Otherwise it should return ``0``. + + There may already be a pending exception set on entry to the callback. In + this case, the callback should return ``0`` with the same exception still + set. This means the callback may not call any other API that can set an + exception unless it saves and clears the exception state first, and restores + it before returning. .. versionadded:: 3.12 |