File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Misc/NEWS.d/next/Documentation Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -686,6 +686,26 @@ and :c:data:`PyType_Type` effectively act as defaults.)
686686 instance, and call the type's :c:member: `~PyTypeObject.tp_free ` function to
687687 free the object itself.
688688
689+ If you may call functions that may set the error indicator, you must use
690+ :c:func: `PyErr_GetRaisedException ` and :c:func: `PyErr_SetRaisedException `
691+ to ensure you don't clobber a preexisting error indicator (the deallocation
692+ could have occurred while processing a different error):
693+
694+ .. code-block :: c
695+
696+ static void
697+ foo_dealloc(foo_object *self)
698+ {
699+ PyObject *et, *ev, *etb;
700+ PyObject *exc = PyErr_GetRaisedException();
701+ ...
702+ PyErr_SetRaisedException(exc);
703+ }
704+
705+ The dealloc handler itself must not raise an exception; if it hits an error
706+ case it should call :c:func: `PyErr_FormatUnraisable ` to log (and clear) an
707+ unraisable exception.
708+
689709 No guarantees are made about when an object is destroyed, except:
690710
691711 * Python will destroy an object immediately or some time after the final
Original file line number Diff line number Diff line change 1+ Document that error indicator may be set in tp_dealloc, and how to avoid
2+ clobbering it.
You can’t perform that action at this time.
0 commit comments