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

unsafe add: will it go back to safe? #191

Closed
keepsimple1 opened this issue Feb 13, 2024 · 6 comments
Closed

unsafe add: will it go back to safe? #191

keepsimple1 opened this issue Feb 13, 2024 · 6 comments

Comments

@keepsimple1
Copy link

pub unsafe fn add(&self, source: impl AsRawSource, interest: Event) -> io::Result<()> {

Although this seems to have happened almost 6 months ago, it's sad that this API changed to be "unsafe". One of my project relies on this API heavily and we cannot upgrade to the latest "polling" due to this unsafe API.

Is there any plan to make this safe again? ("polling" is a great library, I love using it).

@zeenix
Copy link
Member

zeenix commented Feb 13, 2024

unsafe only means it's potentially unsafe and shouldn't stop you from using the library in any way. We can lie that it's safe by not declaring it so but all that will do is give you a false sense of safety.

@zeenix
Copy link
Member

zeenix commented Feb 13, 2024

unsafe only means it's potentially unsafe and shouldn't stop you from using the library in any way. We can lie that it's safe by not declaring it so but all that will do is give you a false sense of safety.

Having said that, looking at the PR that changed it, I'm not sure why this method wasn't just changed to take BorrowedFd instead. @notgull ?

@notgull
Copy link
Member

notgull commented Feb 13, 2024

Since the poller uses the reference to the source without considering its lifetime it's essentially taking a raw pointer. I updated the signature to make this clear.

@zeenix
Copy link
Member

zeenix commented Feb 13, 2024

Since the poller uses the reference to the source without considering its lifetime it's essentially taking a raw pointer. I updated the signature to make this clear.

Thanks for explaining, @notgull. I'm closing this then.

@zeenix zeenix closed this as completed Feb 13, 2024
@keepsimple1
Copy link
Author

That's really fast to close an issue. It will be good to give the user a chance to follow up before closing ;-)

pub fn modify(&self, source: impl AsSource, interest: Event) -> io::Result<()> {

I'm wondering, why is modify() able to take AsSource, not AsRawSource?

@notgull
Copy link
Member

notgull commented Jun 10, 2024

It is able to take a borrowed pointer because it's not kept around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants