Repository navigation
[cpyrt] Raise C++ exceptions from destructors in Python - #170
Open
conrade-ctc wants to merge 1 commit into
Open
conrade-ctc wants to merge 1 commit into
conrade-ctc wants to merge 1 commit into
Conversation
A noexcept(false) destructor that throws aborted the process, because the destructor path did not catch C++ exceptions. __destruct__() now raises the exception as a Python exception. Deallocation reports it through sys.unraisablehook, as CPython does for __del__. Move the exception conversion from CPPMethod into ProxyWrappers, so that both paths use it. Co-developed-with-the-help-of: Claude Code (Opus 5.5, human in the loop)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A throwing
noexcept(false)destructor ended the process withstd::terminate. The destructor path (op_dealloc_nofree→Cpp::Destruct) had no handler, so the exception unwound into CPython's C frames.__destruct__()now raises the C++ exception in Python. The proxy gives up ownership, so a second call does not run the destructor again.sys.unraisablehook, as CPython does for__del__.CPPMethodtoProxyWrappers(SetPyErrFromCppException), so that both paths use it.test33_throwing_destructorcovers these cases. It is xfail on Apple Silicon, like the other tests that throw C++ exceptions.As far as I can tell,
InitializerListConverter::Clearhas the same gap. This PR does not change it.🤖 Done with the help of Claude Code (Opus 5.5, human in the loop)