Repository navigation
Rework crt_fd to be more aligned with io-safety #5789
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4339,7 +4339,7 @@ mod fileio { | |
|
|
||
|
Comment on lines
+4337
to
4339
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consolidate repeated
- let fd = unsafe { crt_fd::Borrowed::borrow_raw(fd) };
+ let fd = borrow_fd(fd); // new safe helperThis also makes it trivial to add additional validation (e.g. negative FD
🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coolreader18 please check this comment
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's not necessarily a benefit to that, since just putting it behind a safe utility function wouldn't actually make it more safe, as each case has its own reason that the unsafe code is okay. |
||
| // TODO: _Py_set_inheritable | ||
|
|
||
| let fd_fstat = crate::common::fileutils::fstat(fd.as_raw()); | ||
| let fd_fstat = crate::common::fileutils::fstat(fd); | ||
|
|
||
| #[cfg(windows)] | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
_get_osfhandle FFI signature should take a plain
i32instead ofBorrowed_get_osfhandleis declared in the CRT asintptr_t _get_osfhandle(int fd);.Passing a
Borrowed<'_>(even thoughrepr(transparent)) in the FFI boundary:.as_raw().and at the call-site:
This keeps the ABI crystal-clear and avoids relying on
repr(transparent)for safety across the language boundary.🤖 Prompt for AI Agents
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.
Huh, impressive, but irrelevant.
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.
@coolreader18 Fair enough! You're focused on the bigger io-safety refactoring here, and that FFI detail can certainly be addressed separately if needed. Thanks for the clarification on priorities.