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

Make Generic UnwindSafe even if its error type isn't #204

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

dfoxfranke
Copy link
Contributor

std::io::Error does not implement UnwindSafe on account of its ability to wrap a Box<dyn Error + Send + Sync>. This infects Generic which in turn infects Channel, which is inconvenient because it means you can't construct a channel pair, pass the receiver side to a child thread, and then handles panics in the child.

But this is silly, because the error parameter to Generic is just a phantom. We aren't really wrapping an error at all, let alone downcasting it to a mutable reference and mucking with the referent. This patch changes the PhantomData<E> to PhantomData<AssertUnwindSafe<E>> so that Generic<F, E> can be UnwindSafe as long as F is.

`std::io::Error` does not implement `UnwindSafe` on account
of its ability to wrap a `Box<dyn Error + Send + Sync>`. This
infects `Generic` which in turn infects `Channel`, which is
inconvenient because it means you can't construct a channel
 pair, pass the receiver side to a child thread, and then
handles panics in the child.

But this is silly, because the error parameter to `Generic`
is just a phantom. We aren't really wrapping an error at all,
let alone downcasting it to a mutable reference and mucking
with the referent. This patch changes the `PhantomData<E>`
to `PhantomData<AssertUnwindSafe<E>>` so that `Generic<F, E>` can
be `UnwindSafe` as long as `F` is.
Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.20%. Comparing base (86c6713) to head (ee61ade).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #204      +/-   ##
==========================================
+ Coverage   85.44%   86.20%   +0.75%     
==========================================
  Files          13       15       +2     
  Lines        1876     2066     +190     
==========================================
+ Hits         1603     1781     +178     
- Misses        273      285      +12     
Flag Coverage Δ
macos-latest 85.47% <ø> (?)
ubuntu-latest 85.80% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

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

Thanks!

@notgull notgull merged commit ac7e5e7 into Smithay:master Aug 10, 2024
14 checks passed
@notgull notgull mentioned this pull request Sep 6, 2024
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.

2 participants