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

SigSet: A new unsafe helper method to create a SigSet from a sigset_t #1741

Merged
merged 2 commits into from
Jul 15, 2022

Commits on Jul 12, 2022

  1. SigSet: A new unsafe helper method to create a SigSet from a sigset_t

    Currently,  the only way to create a `SigSet` from a `sigset_t` object
    is by using pointer casts, like:
    
    ```
    unsafe {
        let sigset = *(&sigset as *const libc::sigset_t as *const SigSet)
    };
    ```
    
    This is un-ergonomic for library creators with interfaces to C.
    So, let's add a new unsafe method that creates a `SigSet` from a
    `libc::sigset_t` object.
    
    We can't implement `From` since converting from `libc::sigset_t` to
    `SigSet` is unsafe, because objects of type `libc::sigset_t` must be
    initialized by calling either `sigemptyset(3)` or `sigfillset(3)`
    before being used. In other case, the results are undefined.
    We can't implement `TryFrom` either, because there is no way to check
    if an object of type `libc::sigset_t` is initialized.
    
    Signed-off-by: German Maglione <gmaglione@redhat.com>
    germag committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    3d44d27 View commit details
    Browse the repository at this point in the history
  2. SigSet: Add the repr(transparent) attribute

    This commit adds the `repr(transparent)` attribute to the `SigSet`
    struct, to make sure that its representation is exactly like the
    `sigset_t` struct from C, in all cases.
    
    Signed-off-by: German Maglione <gmaglione@redhat.com>
    germag committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    b207aae View commit details
    Browse the repository at this point in the history