rust/patches/0018-Add-FnBox-back.patch
2020-01-22 20:24:17 +01:00

174 lines
6.5 KiB
Diff

From 8617310c3c9e192080df6a0c7b4835d3f02e27b9 Mon Sep 17 00:00:00 2001
From: bjorn3 <bjorn3@users.noreply.github.com>
Date: Fri, 1 Nov 2019 20:58:30 +0100
Subject: [PATCH] Add FnBox back
---
src/liballoc/boxed.rs | 13 +++++++++++++
src/libstd/prelude/v1.rs | 2 +-
src/libstd/sys/cloudabi/thread.rs | 2 +-
src/libstd/sys/hermit/thread.rs | 4 ++--
src/libstd/sys/unix/thread.rs | 4 ++--
src/libstd/sys_common/at_exit_imp.rs | 6 +++---
src/libstd/sys_common/mod.rs | 2 +-
src/libstd/sys_common/thread.rs | 2 +-
src/libstd/thread/mod.rs | 2 +-
9 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index ef9b648..e32b870 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -1079,3 +1079,16 @@ impl<F: ?Sized + Future + Unpin> Future for Box<F> {
F::poll(Pin::new(&mut *self), cx)
}
}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+pub trait FnBox<A>: FnOnce<A> {
+ #[stable(feature = "rust1", since = "1.0.0")]
+ extern "rust-call" fn call_box(self: Box<Self>, args: A) -> Self::Output;
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<A, F: FnOnce<A>> FnBox<A> for F {
+ extern "rust-call" fn call_box(self: Box<Self>, args: A) -> Self::Output {
+ <F as FnOnce<A>>::call_once(*self, args)
+ }
+}
diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs
index 3e4cf91..1f50eb3 100644
--- a/src/libstd/prelude/v1.rs
+++ b/src/libstd/prelude/v1.rs
@@ -94,6 +94,6 @@ pub use core::prelude::v1::{
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(no_inline)]
-pub use crate::boxed::Box;
+pub use crate::boxed::{Box, FnBox};
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(no_inline)]
pub use crate::string::{String, ToString};
diff --git a/src/libstd/sys/cloudabi/thread.rs b/src/libstd/sys/cloudabi/thread.rs
index 240b6ea..6f71c6b 100644
--- a/src/libstd/sys/cloudabi/thread.rs
+++ b/src/libstd/sys/cloudabi/thread.rs
@@ -21,7 +21,7 @@ unsafe impl Sync for Thread {}
impl Thread {
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
let p = box p;
let mut native: libc::pthread_t = mem::zeroed();
let mut attr: libc::pthread_attr_t = mem::zeroed();
diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs
index 99a9c83..b8bc392 100644
--- a/src/libstd/sys/hermit/thread.rs
+++ b/src/libstd/sys/hermit/thread.rs
@@ -44,9 +44,9 @@ unsafe impl Sync for Thread {}
pub const DEFAULT_MIN_STACK_SIZE: usize = 262144;
impl Thread {
pub unsafe fn new_with_coreid(
_stack: usize,
- p: Box<dyn FnOnce()>,
+ p: Box<dyn FnBox()>,
core_id: isize,
) -> io::Result<Thread> {
let p = box p;
@@ -67,7 +67,7 @@ impl Thread {
}
}
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
Thread::new_with_coreid(stack, p, -1 /* = no specific core */)
}
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 143cf2f..a6e8faf 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -38,8 +38,8 @@ unsafe fn pthread_attr_setstacksize(_attr: *mut libc::pthread_attr_t,
impl Thread {
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
- pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
+ pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
panic!("Warning: Threads are not yet fully supported, because cranelift doesn't support atomics.");
let p = box p;
let mut native: libc::pthread_t = mem::zeroed();
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs
index cdb72ee..e523333 100644
--- a/src/libstd/sys_common/at_exit_imp.rs
+++ b/src/libstd/sys_common/at_exit_imp.rs
@@ -6,7 +6,7 @@ use crate::mem;
use crate::ptr;
use crate::sys_common::mutex::Mutex;
-type Queue = Vec<Box<dyn FnOnce()>>;
+type Queue = Vec<Box<dyn FnBox()>>;
// NB these are specifically not types from `std::sync` as they currently rely
// on poisoning and this module needs to operate at a lower level than requiring
@@ -53,14 +53,14 @@ pub fn cleanup() {
let queue: Box<Queue> = Box::from_raw(queue);
for to_run in *queue {
// We are not holding any lock, so reentrancy is fine.
- to_run();
+ to_run.call_box(());
}
}
}
}
}
-pub fn push(f: Box<dyn FnOnce()>) -> bool {
+pub fn push(f: Box<dyn FnBox()>) -> bool {
unsafe {
let _guard = LOCK.lock();
if init() {
diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs
index 7a0bcd0..668bef2 100644
--- a/src/libstd/sys_common/mod.rs
+++ b/src/libstd/sys_common/mod.rs
@@ -113,7 +113,7 @@ pub trait FromInner<Inner> {
/// closure will be run once the main thread exits. Returns `Err` to indicate
/// that the closure could not be registered, meaning that it is not scheduled
/// to be run.
-pub fn at_exit<F: FnOnce() + Send + 'static>(f: F) -> Result<(), ()> {
+pub fn at_exit<F: FnBox() + Send + 'static>(f: F) -> Result<(), ()> {
if at_exit_imp::push(Box::new(f)) { Ok(()) } else { Err(()) }
}
diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs
index c638be9..5c18a18 100644
--- a/src/libstd/sys_common/thread.rs
+++ b/src/libstd/sys_common/thread.rs
@@ -10,7 +10,7 @@ pub unsafe fn start_thread(main: *mut u8) {
let _handler = stack_overflow::Handler::new();
// Finally, let's run some code.
- Box::from_raw(main as *mut Box<dyn FnBox()>)()
+ Box::from_raw(main as *mut Box<dyn FnBox()>).call_box(())
}
pub fn min_stack() -> usize {
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 0ffa6ac..4a3e3d6 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -485,7 +485,7 @@ impl Builder {
// returning.
native: Some(imp::Thread::new(
stack_size,
- mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(Box::new(
+ mem::transmute::<Box<dyn FnBox() + 'a>, Box<dyn FnBox() + 'static>>(Box::new(
main,
)),
)?),
--
2.20.1