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

our lazy statics are a panic hazard #138

Closed
eminence opened this issue Jul 29, 2021 · 1 comment · Fixed by #150
Closed

our lazy statics are a panic hazard #138

eminence opened this issue Jul 29, 2021 · 1 comment · Fixed by #150

Comments

@eminence
Copy link
Owner

We have several lazy statics that use .unwrap(), thus they can panic. This is poor API design and should be fixed. See #136 for an example of this.

lazy_static! {
    /// The number of clock ticks per second.
    ///
    /// This is calculated from `sysconf(_SC_CLK_TCK)`.
    static ref TICKS_PER_SECOND: i64 = {
        ticks_per_second().unwrap()
    };
    /// The version of the currently running kernel.
    ///
    /// This is a lazily constructed static.  You can also get this information via
    /// [KernelVersion::new()].
    static ref KERNEL: KernelVersion = {
        KernelVersion::current().unwrap()
    };
    /// Memory page size, in bytes.
    ///
    /// This is calculated from `sysconf(_SC_PAGESIZE)`.
    static ref PAGESIZE: i64 = {
        page_size().unwrap()
    };
}
@tiann
Copy link

tiann commented Sep 30, 2021

Maybe unwrap_or_else to give a default version or to get it from Environment?

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 a pull request may close this issue.

2 participants