-
Notifications
You must be signed in to change notification settings - Fork 670
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
Conversation
v2:
|
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.
The FreeBSD test failure should be fixed by rebasing.
v3:
|
v4:
|
I know it's unrelated to this PR, but |
Ooh, good catch. Could you open an issue for this? |
Done |
Rebase |
it has been suggested to me that |
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.
bors r+
1741: SigSet: A new unsafe helper method to create a SigSet from a sigset_t r=rtzoeller a=germag 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> Co-authored-by: German Maglione <gmaglione@redhat.com>
Build failed: |
@germag can you update the commit adding the test to fix the formatting issue, and also fix the typos in the changelog (e.g. in transparent), since we're updating things anyways? |
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>
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>
v5:
|
Done, thanks |
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.
bors r+
Currently, the only way to create a
SigSet
from asigset_t
objectis by using pointer casts, like:
This is un-ergonomic for library creators with interfaces to C.
So, let's add a new unsafe method that creates a
SigSet
from alibc::sigset_t
object.We can't implement
From
since converting fromlibc::sigset_t
toSigSet
is unsafe, because objects of typelibc::sigset_t
must beinitialized by calling either
sigemptyset(3)
orsigfillset(3)
before being used. In other case, the results are undefined.
We can't implement
TryFrom
either, because there is no way to checkif an object of type
libc::sigset_t
is initialized.Signed-off-by: German Maglione gmaglione@redhat.com