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

Remove lazy_static dependency #706

Closed
briansmith opened this issue Oct 22, 2018 · 1 comment
Closed

Remove lazy_static dependency #706

briansmith opened this issue Oct 22, 2018 · 1 comment

Comments

@briansmith
Copy link
Owner

Originally we used lazy_static in ring::rand because static didn't work for types that implement Drop, as File does. That restriction was removed in rust-lang/rust#44456. I believe it should now be possible to get the same effects using just std::sync::Once.

I see there are some (potential) problems with lazy_static! such as rust-lang-nursery/lazy-static.rs#116 and rust-lang-nursery/lazy-static.rs#117 and rust-lang-nursery/lazy-static.rs#125.

@briansmith
Copy link
Owner Author

@bpowers nicely wrote a PR to do this. That PR taught me a lot about this issue; in particular it taught me that switching to direct of of static mut is a bad idea. I had originally overlooked that using static mut directly would require us to use unsafe where we previously didn't need to.

Regarding the issues with lazy_static linked to above, after I read @bpowers's PR I went back through them again and noticed that the discussion of those issues was pointing out how dangerous direct use of static mut is. Also, the issues with lazy_static have been resolved as of lazy_static 1.2. I upgraded ring's dependency to use version 1.2.

There are simpler and marginally better alternatives to lazy_static, e.g. ones that aren't as obfuscated with macros. Also, there have been proposals to provide a similar mechanism in libstd/libcore. Still, right now lazy_static appears to be, at worst, good enough. So I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant