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

Rollup of 5 pull requests #39907

Closed
wants to merge 16 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl Build {
/// Get the space-separated set of activated features for the standard
/// library.
fn std_features(&self) -> String {
let mut features = "panic-unwind asan lsan msan tsan".to_string();
let mut features = "panic-unwind".to_string();

if self.config.debug_jemalloc {
features.push_str(" debug-jemalloc");
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/src/procedural-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ So this is where quotes comes in. The `ast` argument is a struct that gives us
a representation of our type (which can be either a `struct` or an `enum`).
Check out the [docs](https://docs.rs/syn/0.10.5/syn/struct.MacroInput.html),
there is some useful information there. We are able to get the name of the
type using `ast.ident`. The `quote!` macro let's us write up the Rust code
type using `ast.ident`. The `quote!` macro lets us write up the Rust code
that we wish to return and convert it into `Tokens`. `quote!` let's us use some
really cool templating mechanics; we simply write `#name` and `quote!` will
replace it with the variable named `name`. You can even do some repetition
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,12 @@ pub trait Iterator {
let mut i = self.len();

while let Some(v) = self.next_back() {
if predicate(v) {
return Some(i - 1);
}
// No need for an overflow check here, because `ExactSizeIterator`
// implies that the number of elements fits into a `usize`.
i -= 1;
if predicate(v) {
return Some(i);
}
}
None
}
Expand Down
12 changes: 4 additions & 8 deletions src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ std_unicode = { path = "../libstd_unicode" }
unwind = { path = "../libunwind" }

[target.x86_64-unknown-linux-gnu.dependencies]
rustc_asan = { path = "../librustc_asan", optional = true }
rustc_lsan = { path = "../librustc_lsan", optional = true }
rustc_msan = { path = "../librustc_msan", optional = true }
rustc_tsan = { path = "../librustc_tsan", optional = true }
rustc_asan = { path = "../librustc_asan" }
rustc_lsan = { path = "../librustc_lsan" }
rustc_msan = { path = "../librustc_msan" }
rustc_tsan = { path = "../librustc_tsan" }

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"

[features]
asan = ["rustc_asan"]
backtrace = []
debug-jemalloc = ["alloc_jemalloc/debug"]
jemalloc = ["alloc_jemalloc"]
force_alloc_system = []
lsan = ["rustc_lsan"]
msan = ["rustc_msan"]
panic-unwind = ["panic_unwind"]
tsan = ["rustc_tsan"]
59 changes: 49 additions & 10 deletions src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,20 @@ impl<T> Cursor<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> {
fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
let pos = match style {
SeekFrom::Start(n) => { self.pos = n; return Ok(n) }
SeekFrom::End(n) => self.inner.as_ref().len() as i64 + n,
SeekFrom::Current(n) => self.pos as i64 + n,
let (base_pos, offset) = match style {
SeekFrom::Start(n) => { self.pos = n; return Ok(n); }
SeekFrom::End(n) => (self.inner.as_ref().len() as u64, n),
SeekFrom::Current(n) => (self.pos, n),
};

if pos < 0 {
Err(Error::new(ErrorKind::InvalidInput,
"invalid seek to a negative position"))
let new_pos = if offset >= 0 {
base_pos.checked_add(offset as u64)
} else {
self.pos = pos as u64;
Ok(self.pos)
base_pos.checked_sub((offset.wrapping_neg()) as u64)
};
match new_pos {
Some(n) => {self.pos = n; Ok(self.pos)}
None => Err(Error::new(ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position"))
}
}
}
Expand Down Expand Up @@ -526,6 +528,43 @@ mod tests {
assert_eq!(r.write(&[3]).unwrap(), 0);
}

#[test]
fn seek_past_i64() {
let buf = [0xff];
let mut r = Cursor::new(&buf[..]);
assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6);
assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6);
assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006);
assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006);
assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err());
assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6);

let mut r = Cursor::new(vec![10]);
assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6);
assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6);
assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006);
assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006);
assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err());
assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6);

let mut buf = [0];
let mut r = Cursor::new(&mut buf[..]);
assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6);
assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6);
assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006);
assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006);
assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err());
assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6);

let mut r = Cursor::new(vec![10].into_boxed_slice());
assert_eq!(r.seek(SeekFrom::Start(6)).unwrap(), 6);
assert_eq!(r.seek(SeekFrom::Current(0x7ffffffffffffff0)).unwrap(), 0x7ffffffffffffff6);
assert_eq!(r.seek(SeekFrom::Current(0x10)).unwrap(), 0x8000000000000006);
assert_eq!(r.seek(SeekFrom::Current(0)).unwrap(), 0x8000000000000006);
assert!(r.seek(SeekFrom::Current(0x7ffffffffffffffd)).is_err());
assert_eq!(r.seek(SeekFrom::Current(-0x8000000000000000)).unwrap(), 6);
}

#[test]
fn seek_before_0() {
let buf = [0xff];
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Once {
}

// Once we've enqueued ourselves, wait in a loop.
// Aftewards reload the state and continue with what we
// Afterwards reload the state and continue with what we
// were doing from before.
while !node.signaled.load(Ordering::SeqCst) {
thread::park();
Expand Down
38 changes: 9 additions & 29 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,41 +483,21 @@ pub fn home_dir() -> Option<PathBuf> {
target_os = "nacl",
target_os = "emscripten")))]
unsafe fn fallback() -> Option<OsString> {
#[cfg(not(target_os = "solaris"))]
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
buf: &mut Vec<c_char>) -> Option<()> {
let mut result = ptr::null_mut();
match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
buf.capacity(),
&mut result) {
0 if !result.is_null() => Some(()),
_ => None
}
}

#[cfg(target_os = "solaris")]
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
buf: &mut Vec<c_char>) -> Option<()> {
// getpwuid_r semantics is different on Illumos/Solaris:
// http://illumos.org/man/3c/getpwuid_r
let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(),
buf.capacity());
if result.is_null() { None } else { Some(()) }
}

let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
n if n < 0 => 512 as usize,
n => n as usize,
};
let mut buf = Vec::with_capacity(amt);
let mut passwd: libc::passwd = mem::zeroed();

if getpwduid_r(libc::getuid(), &mut passwd, &mut buf).is_some() {
let ptr = passwd.pw_dir as *const _;
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
Some(OsStringExt::from_vec(bytes))
} else {
None
let mut result = ptr::null_mut();
match libc::getpwuid_r(libc::getuid(), &mut passwd, buf.as_mut_ptr(),
buf.capacity(), &mut result) {
0 if !result.is_null() => {
let ptr = passwd.pw_dir as *const _;
let bytes = CStr::from_ptr(ptr).to_bytes().to_vec();
Some(OsStringExt::from_vec(bytes))
},
_ => None,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use mem;
/// # Initialization and Destruction
///
/// Initialization is dynamically performed on the first call to `with()`
/// within a thread, and values support destructors which will be run when a
/// thread exits.
/// within a thread, and values that implement `Drop` get destructed when a
/// thread exits. Some caveats apply, which are explained below.
///
/// # Examples
///
Expand Down
4 changes: 0 additions & 4 deletions src/rustc/std_shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ core = { path = "../../libcore" }

# Reexport features from std
[features]
asan = ["std/asan"]
backtrace = ["std/backtrace"]
debug-jemalloc = ["std/debug-jemalloc"]
jemalloc = ["std/jemalloc"]
force_alloc_system = ["std/force_alloc_system"]
lsan = ["std/lsan"]
msan = ["std/msan"]
panic-unwind = ["std/panic-unwind"]
tsan = ["std/tsan"]