-
Notifications
You must be signed in to change notification settings - Fork 13.4k
std: move io
module out of pal
, get rid of sys_common::io
#135696
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,3 @@ impl<'a> IoSliceMut<'a> { | |
self.0 | ||
} | ||
} | ||
|
||
pub fn is_terminal<T>(_: &T) -> bool { | ||
false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 17 additions & 21 deletions
38
library/std/src/sys/pal/solid/io.rs → library/std/src/sys/io/io_slice/windows.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,82 @@ | ||
use libc::c_void; | ||
|
||
use super::abi::sockets::iovec; | ||
use crate::marker::PhantomData; | ||
use crate::slice; | ||
use crate::sys::c; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(transparent)] | ||
pub struct IoSlice<'a> { | ||
vec: iovec, | ||
vec: c::WSABUF, | ||
_p: PhantomData<&'a [u8]>, | ||
} | ||
|
||
impl<'a> IoSlice<'a> { | ||
#[inline] | ||
pub fn new(buf: &'a [u8]) -> IoSlice<'a> { | ||
assert!(buf.len() <= u32::MAX as usize); | ||
IoSlice { | ||
vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() }, | ||
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_ptr() as *mut u8 }, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn advance(&mut self, n: usize) { | ||
if self.vec.iov_len < n { | ||
if (self.vec.len as usize) < n { | ||
panic!("advancing IoSlice beyond its length"); | ||
} | ||
|
||
unsafe { | ||
self.vec.iov_len -= n; | ||
self.vec.iov_base = self.vec.iov_base.add(n); | ||
self.vec.len -= n as u32; | ||
self.vec.buf = self.vec.buf.add(n); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub const fn as_slice(&self) -> &'a [u8] { | ||
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct IoSliceMut<'a> { | ||
vec: iovec, | ||
vec: c::WSABUF, | ||
_p: PhantomData<&'a mut [u8]>, | ||
} | ||
|
||
impl<'a> IoSliceMut<'a> { | ||
#[inline] | ||
pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { | ||
assert!(buf.len() <= u32::MAX as usize); | ||
IoSliceMut { | ||
vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() }, | ||
vec: c::WSABUF { len: buf.len() as u32, buf: buf.as_mut_ptr() }, | ||
_p: PhantomData, | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn advance(&mut self, n: usize) { | ||
if self.vec.iov_len < n { | ||
if (self.vec.len as usize) < n { | ||
panic!("advancing IoSliceMut beyond its length"); | ||
} | ||
|
||
unsafe { | ||
self.vec.iov_len -= n; | ||
self.vec.iov_base = self.vec.iov_base.add(n); | ||
self.vec.len -= n as u32; | ||
self.vec.buf = self.vec.buf.add(n); | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } | ||
} | ||
|
||
#[inline] | ||
pub const fn into_slice(self) -> &'a mut [u8] { | ||
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) } | ||
} | ||
|
||
#[inline] | ||
pub fn as_mut_slice(&mut self) -> &mut [u8] { | ||
unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) } | ||
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) } | ||
} | ||
} | ||
|
||
pub fn is_terminal<T>(_: &T) -> bool { | ||
false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::os::fd::{AsFd, AsRawFd}; | ||
|
||
pub fn is_terminal(fd: &impl AsFd) -> bool { | ||
let fd = fd.as_fd(); | ||
hermit_abi::isatty(fd.as_raw_fd()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use crate::os::fd::{AsFd, AsRawFd}; | ||
|
||
pub fn is_terminal(fd: &impl AsFd) -> bool { | ||
let fd = fd.as_fd(); | ||
unsafe { libc::isatty(fd.as_raw_fd()) != 0 } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn is_terminal<T>(_: &T) -> bool { | ||
false | ||
} |
84 changes: 1 addition & 83 deletions
84
library/std/src/sys/pal/windows/io.rs → ...ary/std/src/sys/io/is_terminal/windows.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.