-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy path0018-Add-FnBox-back.patch
174 lines (159 loc) · 6.58 KB
/
0018-Add-FnBox-back.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From 8617310c3c9e192080df6a0c7b4835d3f02e27b9 Mon Sep 17 00:00:00 2001
From: bjorn3 <[email protected]>
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.");
+ println!("Spawned thread");
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