Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better exception and error handling for capsules #3825

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

Skylion007
Copy link
Collaborator

@Skylion007 Skylion007 commented Mar 24, 2022

Description

  • This solves several issues when dealing with capsules. Firstly, we were leaving the pybind11 in a bad exception state when we throw pybind11_fail without clearing the error first. We really should be throwing error_already_set to ensure that exception messages are as consistent and informative as vanilla cpython.
  • There really isn't a good reason to be catching these errors so the changes should be pretty backwards compatible. In fact, a lot of the invalid error states occurred because our test suite never hit them in production.
  • This guards against some nasty segfaults that could occur when mishandling capsules.
  • Many of the python capsule calls only return null on error states which makes exception handling trivial. There was only one case where I had to add an additional pybind11_fail as a catch.
  • Finally while browsing the repo, I found one more missing std::move and added that in.

Suggested changelog entry:

* The bindings for capsules now have more consistent exception handling.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this cleanup, the revised code makes a lot more sense!
I'll try to run this through our global testing tonight, but if you need this before I have the results, please go ahead.

@rwgk
Copy link
Collaborator

rwgk commented Mar 24, 2022

Suggested changelogentry:
PyCapsules standing bindings now have more consistent exception handling.

standing?

standard?

Maybe: py::capsule now has more consistent exception handling.

?

@rwgk
Copy link
Collaborator

rwgk commented Mar 25, 2022

The test ID for the global testing is OCL:437135289:BASE:437101826:1648173046939:234ba7aa, 21:00 batch.

@rwgk
Copy link
Collaborator

rwgk commented Mar 25, 2022

The global testing finished without finding any issues.

@Skylion007
Copy link
Collaborator Author

@rwgk Fixed spelling errors in the PR description.

Copy link
Collaborator

@henryiii henryiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic to me. :)

@Skylion007 Skylion007 changed the title bugfix: better exception and error handling for capsules fix: better exception and error handling for capsules Mar 25, 2022
@Skylion007 Skylion007 merged commit 146695a into pybind:master Mar 25, 2022
@Skylion007 Skylion007 deleted the skylion007/fix-capsule-errors branch March 25, 2022 14:55
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Mar 25, 2022
henryiii pushed a commit to henryiii/pybind11 that referenced this pull request Mar 25, 2022
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants