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

Rename Flags EventFlag and MemFdCreateFlag #2476

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2476.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename Flags `EventFlag` to `EvFlags`, and `MemFdCreateFlag` to `MFdFlags`
14 changes: 9 additions & 5 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ libc_bitflags! {
/// Event flags. See the man page for details.
// There's no useful documentation we can write for the individual flags
// that wouldn't simply be repeating the man page.
pub struct EventFlag: type_of_event_flag {
pub struct EvFlags: type_of_event_flag {
#[allow(missing_docs)]
EV_ADD;
#[allow(missing_docs)]
Expand Down Expand Up @@ -216,6 +216,10 @@ libc_bitflags! {
}
}

#[deprecated(since = "0.30.0", note = "Use `EvFlags instead`")]
/// The deprecated EventFlag type alias
pub type EventFlag = EvFlags;

libc_bitflags!(
/// Filter-specific flags. See the man page for details.
// There's no useful documentation we can write for the individual flags
Expand Down Expand Up @@ -347,7 +351,7 @@ impl KEvent {
pub fn new(
ident: uintptr_t,
filter: EventFilter,
flags: EventFlag,
flags: EvFlags,
fflags: FilterFlag,
data: intptr_t,
udata: intptr_t,
Expand Down Expand Up @@ -382,8 +386,8 @@ impl KEvent {

/// Flags control what the kernel will do when this event is added with
/// [`Kqueue::kevent`].
pub fn flags(&self) -> EventFlag {
EventFlag::from_bits(self.kevent.flags).unwrap()
pub fn flags(&self) -> EvFlags {
EvFlags::from_bits(self.kevent.flags).unwrap()
}

/// Filter-specific flags.
Expand Down Expand Up @@ -443,7 +447,7 @@ pub fn ev_set(
ev: &mut KEvent,
ident: usize,
filter: EventFilter,
flags: EventFlag,
flags: EvFlags,
fflags: FilterFlag,
udata: intptr_t,
) {
Expand Down
8 changes: 6 additions & 2 deletions src/sys/memfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{NixPath, Result};

libc_bitflags!(
/// Options that change the behavior of [`memfd_create`].
pub struct MemFdCreateFlag: libc::c_uint {
pub struct MFdFlags: libc::c_uint {
/// Set the close-on-exec ([`FD_CLOEXEC`]) flag on the new file descriptor.
///
/// By default, the new file descriptor is set to remain open across an [`execve`]
Expand Down Expand Up @@ -74,6 +74,10 @@ libc_bitflags!(
}
);

#[deprecated(since = "0.30.0", note = "Use `MFdFlags instead`")]
/// The deprecated MemFdCreateFlag type alias
pub type MemFdCreateFlag = MFdFlags;

/// Creates an anonymous file that lives in memory, and return a file-descriptor to it.
///
/// The file behaves like a regular file, and so can be modified, truncated, memory-mapped, and so on.
Expand All @@ -85,7 +89,7 @@ libc_bitflags!(
#[inline] // Delays codegen, preventing linker errors with dylibs and --no-allow-shlib-undefined
pub fn memfd_create<P: NixPath + ?Sized>(
name: &P,
flags: MemFdCreateFlag,
flags: MFdFlags,
) -> Result<OwnedFd> {
let res = name.with_nix_path(|cstr| {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ pub enum SigevNotify<'fd> {
/// Will be contained in the kevent's `udata` field.
udata: libc::intptr_t,
/// Flags that will be set on the delivered event. See `kevent(2)`.
flags: crate::sys::event::EventFlag
flags: crate::sys::event::EvFlags
},
/// Notify by delivering a signal to a thread.
#[cfg(any(
Expand Down
6 changes: 3 additions & 3 deletions test/sys/test_event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libc::intptr_t;
use nix::sys::event::{EventFilter, EventFlag, FilterFlag, KEvent};
use nix::sys::event::{EvFlags, EventFilter, FilterFlag, KEvent};

#[test]
fn test_struct_kevent() {
Expand All @@ -11,7 +11,7 @@ fn test_struct_kevent() {
let actual = KEvent::new(
0xdead_beef,
EventFilter::EVFILT_READ,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asomers, any idea what we should do to things like this enum EventFilter?

use nix::sys::event::{EvFlags, EventFilter};

Honestly, it feels weird to me when putting them together 🥲, one aims to be short, typical C-style, one aims to be self-explanatory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If does seem odd now. I think they'll need hard to remember like this. We should probably make the two names more consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

EventFlag::EV_ONESHOT | EventFlag::EV_ADD,
EvFlags::EV_ONESHOT | EvFlags::EV_ADD,
FilterFlag::NOTE_CHILD | FilterFlag::NOTE_EXIT,
data,
udata,
Expand All @@ -32,7 +32,7 @@ fn test_kevent_filter() {
let actual = KEvent::new(
0xdead_beef,
EventFilter::EVFILT_READ,
EventFlag::EV_ONESHOT | EventFlag::EV_ADD,
EvFlags::EV_ONESHOT | EvFlags::EV_ADD,
FilterFlag::NOTE_CHILD | FilterFlag::NOTE_EXIT,
0x1337,
udata,
Expand Down
5 changes: 2 additions & 3 deletions test/sys/test_memfd.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[test]
fn test_memfd_create() {
use nix::sys::memfd::memfd_create;
use nix::sys::memfd::MemFdCreateFlag;
use nix::sys::memfd::MFdFlags;
use nix::unistd::lseek;
use nix::unistd::read;
use nix::unistd::{write, Whence};

let fd =
memfd_create("test_memfd_create_name", MemFdCreateFlag::MFD_CLOEXEC)
.unwrap();
memfd_create("test_memfd_create_name", MFdFlags::MFD_CLOEXEC).unwrap();
let contents = b"hello";
assert_eq!(write(&fd, contents).unwrap(), 5);

Expand Down
Loading