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.
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
Panic handling: thread safety; set hook once and not repeatedly #1037
base: master
Are you sure you want to change the base?
Panic handling: thread safety; set hook once and not repeatedly #1037
Changes from 16 commits
8e2e943
0e1d6f5
78193bd
3a6d430
1e3f2e9
681cde9
24d557c
a1b239b
e827eaa
8eeb62d
d33975c
bf22726
8f3c96e
8dd0041
5b0b5c0
bd32724
e0270e9
6389f14
8715866
c282385
b0d5a9c
57abf8d
f7d10c1
7323689
e5f2db8
5ce6318
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use raw pointers, lifetimes are thrown away, so the extension with
assume_static_lifetime
is no longer needed. Just insert the raw pointer directly.Furthermore, which function is unsafe depends a bit on how we lay out the responsibilities. I'd spontaneously have said that
get_last()
should be unsafe since it's the one introducing UB when dereferencing a dangling pointer, but on the other hand there's no real invariant the caller can uphold inside the panic hook; they rely on everything being done correctly inhandle_panic
.As such, this probably makes sense?
@lilizoey opinions on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a hundred percent certain why, but inserting the raw pointer without the call to
assume_static_lifetime
results in a compiler error:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has to do with the lifetime of the function trait itself, but I'm not certain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it's a bit of a tossup, at least one of
push_function
andget_last
have to be unsafe for sure. I think this works as is though. The api isn't the easiest to use safely but we also dont use this anywhere else, so it's probably fine.Yeah, you can do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still pending 🙂
First, let's not use
as
cast to go from reference to pointer, there's a dedicated function for it. Unfortunately, we can't useptr::cast()
for the second conversion, as that implicitly needsSized
for some reason.Using intermediate variables for clarity, this then becomes:
Sidenote:
as _
casts are a rusty crowbar which is very dangerous, let's write types explicitly in this context, not with_
. It's ironic thatmem::transmute
got a lint to specify types explicitly, but pointer bending at will is totally not seen as a problem, not even in clippy. (I'm not saying it should beunsafe
, of course; a lint would be nice though).