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

epoll event constants should be declared as u32 #3462

Closed
tremon015 opened this issue Dec 4, 2023 · 3 comments · Fixed by #3466
Closed

epoll event constants should be declared as u32 #3462

tremon015 opened this issue Dec 4, 2023 · 3 comments · Fixed by #3466
Labels
C-bug Category: bug

Comments

@tremon015
Copy link

The current implementation declares all EPOLL* event constants as c_int, but this isn't very useful given that the accompanying field in struct epoll_event is declared as u32.

pub const EPOLLIN: c_int = 0x1;

pub struct epoll_event {
    pub events: u32,
    pub u64: u64,
}

This makes using these constants very unergonomic:

error[E0308]: mismatched types
   --> src/bin/hld.rs:256:46
    |
256 |          if event.events & EPOLLIN == EPOLLIN {
    |                            ^^^^^^^ expected `u32`, found `i32`

error[E0277]: no implementation for `u32 & i32`
   --> src/bin/hld.rs:256:44
    |
256 |          if event.events & EPOLLIN == EPOLLIN {
    |                          ^ no implementation for `u32 & i32`
    |

The first thing every user of these constants will do is redefine them as u32. Can this be done in the libc crate itself? This applies to all EPOLL* event descriptors and input flags, but not the EPOLL_CTL_* operation constants.

@tremon015 tremon015 added the C-bug Category: bug label Dec 4, 2023
@tremon015
Copy link
Author

Taking a look at the kernel source itself, all values are of type __poll_t: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/eventpoll.h

And the __poll_t type is

typedef unsigned __bitwise __poll_t;

from https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/types.h#n59

@devnexen
Copy link
Contributor

devnexen commented Dec 8, 2023

Feel free to open a PR :)

@tremon015
Copy link
Author

Well, I can create a pull request with the straightforward s/// easily. However, I'm completely unsure of the further ramifications of this change. So I would really appreciate it if other people approach this request with due care :p

bors added a commit that referenced this issue Jan 7, 2024
…Titor

update epoll constants to match epoll_event struct

Change the type of the EPOLL* event constants to match the type of the events field in struct epoll_event (i.e. u32).

closes: #3462
@bors bors closed this as completed in 9a40025 Jan 7, 2024
Andy-Python-Programmer pushed a commit to Andy-Python-Programmer/libc that referenced this issue Mar 24, 2024
Change the type of the EPOLL* event constants to match the type of
the events field in struct epoll_event (i.e. u32).

closes: rust-lang#3462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants