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

Symbol::<'lib, T>::into_raw() is not unsafe #111

Open
yshui opened this issue Sep 8, 2022 · 2 comments
Open

Symbol::<'lib, T>::into_raw() is not unsafe #111

yshui opened this issue Sep 8, 2022 · 2 comments

Comments

@yshui
Copy link

yshui commented Sep 8, 2022

If a raw symbol is created and never used, it's impossible to cause undefined behavior, even if the library is unloaded - creating a raw symbol isn't unsafe, using it is.

@nagisa
Copy link
Owner

nagisa commented Sep 8, 2022

So, the somewhat unfortunate thing is that there’s no other place to put an unsafe for using a os::*::Symbol – this today happens through a Deref. And so there must be some location that imposes an invariant of not using the contents of the os::*::Symbol past the point when the Library is unloaded.

For os::*::Library this is part of its get method, however the top-level Library and Symbol both prevent this class of mistakes, and so the only reasonable location to surface this invariant is in into_raw.

Hopefully that makes sense?

(NB: this is largely closely related to #13 – yes Symbol should not implement a Deref, but as far as I’m aware there isn’t a viable alternative in today’s Rust)

@yshui
Copy link
Author

yshui commented Sep 8, 2022

Hmm, I think I understand your point. So in Symbol<T>, if there is a way to force T to be a raw pointer/unsafe function pointer, would that solve this dilemma?

Actually, since Library::get is already unsafe, could we say if the user assigned T a safe type, it's their mistake?

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

No branches or pull requests

2 participants