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 13 pull requests #77210

Closed
wants to merge 34 commits into from
Closed
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2ac89ff
Point at named argument not found when using `format_args_capture` in…
estebank Sep 8, 2020
094d67a
Add accessors to Command.
ehuss Sep 21, 2020
945a732
Update mdBook
camelid Sep 23, 2020
50d9663
Update cargo
ehuss Sep 24, 2020
ecf3895
Add MIPS asm! support
tesuji Sep 16, 2020
9baa601
Add `x.py setup`
jyn514 Sep 12, 2020
bab15f7
Remove std::io::lazy::Lazy in favour of SyncOnceCell
m-ou-se Sep 24, 2020
e9b25f5
Add test to check stdout flushing during shutdown.
m-ou-se Sep 24, 2020
45700a9
Drop use of Arc from Stdin and Stdout.
m-ou-se Sep 24, 2020
12ada5c
Remove TrustedLen requirement from BuilderMethods::switch
est31 Sep 24, 2020
6f9c132
Call ReentrantMutex::init() in stdout().
m-ou-se Sep 24, 2020
47843f5
update Miri
RalfJung Sep 24, 2020
257f6e5
Reopen standard streams when they are closed on Unix
tmiasko Sep 25, 2020
0d2521a
Add `const_fn_floating_point_arithmetic`
ecstatic-morse Sep 23, 2020
2049052
Put floating point arithmetic behind its own feature gate
ecstatic-morse Sep 23, 2020
6a52c09
Add new feature gate to standard library
ecstatic-morse Sep 23, 2020
b428f28
Bless tests
ecstatic-morse Sep 23, 2020
4cac90c
Move const fn floating point test out of `min_const_fn`
ecstatic-morse Sep 23, 2020
659028f
Use proper issue for `const_fn_floating_point_arithmetic`
ecstatic-morse Sep 23, 2020
187162e
Add missing code examples on slice iter types
GuillaumeGomez Sep 22, 2020
900daba
Remove stray word from `ClosureKind::extends` docs
LingMan Sep 25, 2020
4a63054
Rollup merge of #75295 - tmiasko:fds, r=Amanieu
jonas-schievink Sep 25, 2020
1097169
Rollup merge of #76485 - estebank:format_arg_capture_spans, r=davidtwco
jonas-schievink Sep 25, 2020
fb51bde
Rollup merge of #76631 - jyn514:x.py-setup, r=Mark-Simulacrum
jonas-schievink Sep 25, 2020
4564dff
Rollup merge of #76839 - lzutao:mips-asm, r=Amanieu
jonas-schievink Sep 25, 2020
493c990
Rollup merge of #77029 - ehuss:command-access, r=Mark-Simulacrum
jonas-schievink Sep 25, 2020
1a95d28
Rollup merge of #77076 - GuillaumeGomez:missing-code-examples-slice-i…
jonas-schievink Sep 25, 2020
910412e
Rollup merge of #77122 - ecstatic-morse:const-fn-arithmetic, r=RalfJu…
jonas-schievink Sep 25, 2020
ea4422c
Rollup merge of #77127 - camelid:update-mdbook, r=Dylan-DPC
jonas-schievink Sep 25, 2020
e5514af
Rollup merge of #77129 - ehuss:update-cargo, r=ehuss
jonas-schievink Sep 25, 2020
96d2c8b
Rollup merge of #77154 - fusion-engineering-forks:lazy-stdio, r=dtolnay
jonas-schievink Sep 25, 2020
4ac715d
Rollup merge of #77161 - est31:swich_len_already_trusted, r=petrochenkov
jonas-schievink Sep 25, 2020
43045ce
Rollup merge of #77166 - RalfJung:miri, r=RalfJung
jonas-schievink Sep 25, 2020
3537ee3
Rollup merge of #77204 - LingMan:patch-3, r=jonas-schievink
jonas-schievink Sep 25, 2020
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
63 changes: 0 additions & 63 deletions library/std/src/io/lazy.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -285,7 +285,6 @@ mod buffered;
mod cursor;
mod error;
mod impls;
mod lazy;
pub mod prelude;
mod stdio;
mod util;
76 changes: 40 additions & 36 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,11 @@ use crate::io::prelude::*;

use crate::cell::RefCell;
use crate::fmt;
use crate::io::lazy::Lazy;
use crate::io::{self, BufReader, Initializer, IoSlice, IoSliceMut, LineWriter};
use crate::sync::{Arc, Mutex, MutexGuard, Once};
use crate::lazy::SyncOnceCell;
use crate::sync::{Mutex, MutexGuard};
use crate::sys::stdio;
use crate::sys_common;
use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
use crate::thread::LocalKey;

@@ -217,7 +218,7 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Stdin {
inner: Arc<Mutex<BufReader<StdinRaw>>>,
inner: &'static Mutex<BufReader<StdinRaw>>,
}

/// A locked reference to the `Stdin` handle.
@@ -292,15 +293,11 @@ pub struct StdinLock<'a> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stdin() -> Stdin {
static INSTANCE: Lazy<Mutex<BufReader<StdinRaw>>> = Lazy::new();
return Stdin {
inner: unsafe { INSTANCE.get(stdin_init).expect("cannot access stdin during shutdown") },
};

fn stdin_init() -> Arc<Mutex<BufReader<StdinRaw>>> {
// This must not reentrantly access `INSTANCE`
let stdin = stdin_raw();
Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
static INSTANCE: SyncOnceCell<Mutex<BufReader<StdinRaw>>> = SyncOnceCell::new();
Stdin {
inner: INSTANCE.get_or_init(|| {
Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin_raw()))
}),
}
}

@@ -476,7 +473,7 @@ pub struct Stdout {
// FIXME: this should be LineWriter or BufWriter depending on the state of
// stdout (tty or not). Note that if this is not line buffered it
// should also flush-on-panic or some form of flush-on-abort.
inner: Arc<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>>,
inner: &'static ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>,
}

/// A locked reference to the `Stdout` handle.
@@ -534,19 +531,27 @@ pub struct StdoutLock<'a> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn stdout() -> Stdout {
static INSTANCE: Lazy<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = Lazy::new();
return Stdout {
inner: unsafe { INSTANCE.get(stdout_init).expect("cannot access stdout during shutdown") },
};

fn stdout_init() -> Arc<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> {
// This must not reentrantly access `INSTANCE`
let stdout = stdout_raw();
unsafe {
let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
ret.init();
ret
}
static INSTANCE: SyncOnceCell<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> =
SyncOnceCell::new();
Stdout {
inner: INSTANCE.get_or_init(|| unsafe {
let _ = sys_common::at_exit(|| {
if let Some(instance) = INSTANCE.get() {
// Flush the data and disable buffering during shutdown
// by replacing the line writer by one with zero
// buffering capacity.
// We use try_lock() instead of lock(), because someone
// might have leaked a StdoutLock, which would
// otherwise cause a deadlock here.
if let Some(lock) = instance.try_lock() {
*lock.borrow_mut() = LineWriter::with_capacity(0, stdout_raw());
}
}
});
let r = ReentrantMutex::new(RefCell::new(LineWriter::new(stdout_raw())));
r.init();
r
}),
}
}

@@ -741,16 +746,15 @@ pub fn stderr() -> Stderr {
//
// This has the added benefit of allowing `stderr` to be usable during
// process shutdown as well!
static INSTANCE: ReentrantMutex<RefCell<StderrRaw>> =
unsafe { ReentrantMutex::new(RefCell::new(stderr_raw())) };

// When accessing stderr we need one-time initialization of the reentrant
// mutex. Afterwards we can just always use the now-filled-in `INSTANCE` value.
static INIT: Once = Once::new();
INIT.call_once(|| unsafe {
INSTANCE.init();
});
Stderr { inner: &INSTANCE }
static INSTANCE: SyncOnceCell<ReentrantMutex<RefCell<StderrRaw>>> = SyncOnceCell::new();

Stderr {
inner: INSTANCE.get_or_init(|| unsafe {
let r = ReentrantMutex::new(RefCell::new(stderr_raw()));
r.init();
r
}),
}
}

impl Stderr {
14 changes: 14 additions & 0 deletions src/test/ui/stdout-during-shutdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-pass
// check-run-results

#![feature(rustc_private)]

extern crate libc;

fn main() {
extern "C" fn bye() {
print!(", world!");
}
unsafe { libc::atexit(bye) };
print!("hello");
}
1 change: 1 addition & 0 deletions src/test/ui/stdout-during-shutdown.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello, world!