@@ -4,10 +4,11 @@ compile_error!("The features `export-globals` and `import-globals` cannot be use
4
4
#[ cfg( any( feature = "export-globals" , feature = "import-globals" ) ) ]
5
5
pub use paste:: paste;
6
6
7
- //===== crimes
7
+ //==============================================================================
8
+ // Wrappers
9
+ //==============================================================================
8
10
9
- /// This gets rid of Rust compiler errors when trying to refer to an `extern`
10
- /// static. That error is there for a reason, but we're doing crimes.
11
+ /// Wrapper around an `extern` `static` ref to avoid requiring `unsafe` for imported globals.
11
12
pub struct TrustedExtern < T : ' static > ( pub & ' static T ) ;
12
13
13
14
use std:: ops:: Deref ;
@@ -19,17 +20,26 @@ impl<T> Deref for TrustedExtern<T> {
19
20
}
20
21
}
21
22
23
+ /// Wrapper around an `extern` `static` double-ref to avoid requiring `unsafe` for imported globals.
24
+ ///
25
+ /// The reason we have a double-ref is that when exporting thread-locals, the dynamic symbol is
26
+ /// already a ref. Then, in our own static, we can only access the address of that ref, not its
27
+ /// value (since its value is only known as load time, not compile time).
28
+ ///
29
+ /// As a result, imported thread-locals have an additional layer of indirection.
22
30
pub struct TrustedExternDouble < T : ' static > ( pub & ' static & ' static T ) ;
23
31
24
32
impl < T > Deref for TrustedExternDouble < T > {
25
33
type Target = T ;
26
34
fn deref ( & self ) -> & Self :: Target {
27
- // autoderef plays a role here
35
+ // autoderef goes brrr
28
36
self . 0
29
37
}
30
38
}
31
39
32
- //===== thread-locals
40
+ //==============================================================================
41
+ // Thread-locals
42
+ //==============================================================================
33
43
34
44
#[ cfg( not( any( feature = "import-globals" , feature = "export-globals" ) ) ) ]
35
45
#[ macro_export]
@@ -99,7 +109,9 @@ macro_rules! thread_local_inner {
99
109
} ;
100
110
}
101
111
102
- //===== process-locals (statics)
112
+ //==============================================================================
113
+ // Process-locals (statics)
114
+ //==============================================================================
103
115
104
116
#[ cfg( all( not( feature = "import-globals" ) , not( feature = "export-globals" ) ) ) ]
105
117
#[ macro_export]
@@ -196,31 +208,37 @@ macro_rules! process_local_inner_mut {
196
208
} ;
197
209
}
198
210
199
- //===== soprintln!
211
+ //==============================================================================
212
+ // soprintln
213
+ //==============================================================================
200
214
201
- #[ no_mangle]
215
+ /// Note: there's one copy of this static per shared object on purpose — that's the one
216
+ /// static we DON'T want to deduplicate.
217
+ #[ used]
202
218
static SHARED_OBJECT_ID_REF : u64 = 0 ;
203
219
204
220
/// Returns a unique identifier for the current shared object
205
- /// (based on the address of the `shared_object_id_ref` function ).
221
+ /// (based on the address of the `SHARED_OBJECT_ID_REF` static ).
206
222
pub fn shared_object_id ( ) -> u64 {
207
223
& SHARED_OBJECT_ID_REF as * const _ as u64
208
224
}
209
225
226
+ /// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
210
227
#[ cfg( feature = "import-globals" ) ]
211
228
pub static RUBICON_MODE : & str = "I" ; // "import"
212
229
230
+ /// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
213
231
#[ cfg( feature = "export-globals" ) ]
214
232
pub static RUBICON_MODE : & str = "E" ; // "export"
215
233
234
+ /// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
216
235
#[ cfg( not( any( feature = "import-globals" , feature = "export-globals" ) ) ) ]
217
236
pub static RUBICON_MODE : & str = "N" ; // "normal"
218
237
219
238
#[ cfg( all( feature = "import-globals" , feature = "export-globals" ) ) ]
220
239
compile_error ! ( "The features \" import-globals\" and \" export-globals\" are mutually exclusive" ) ;
221
240
222
- /// A u64 value, with an automatically-generated foreground and background color,
223
- /// with a `Display` implementation that prints the value with 24-bit color ANSI escape codes.
241
+ /// A `u64` whose 24-bit ANSI color is determined by its value.
224
242
pub struct Beacon < ' a > {
225
243
fg : ( u8 , u8 , u8 ) ,
226
244
bg : ( u8 , u8 , u8 ) ,
@@ -345,6 +363,12 @@ macro_rules! soprintln {
345
363
} ;
346
364
}
347
365
366
+ /// `soprintln!` prints a message prefixed by a truncated timestamp, shared object ID and thread ID.
367
+ ///
368
+ /// It is costly, which is why it's behind a cargo feature AND an environment variable.
369
+ ///
370
+ /// To see soprintln output, enable the `soprintln` cargo feature, and set the `SO_PRINTLN`
371
+ /// environment variable to `1`.
348
372
#[ macro_export]
349
373
#[ cfg( not( feature = "soprintln" ) ) ]
350
374
macro_rules! soprintln {
0 commit comments