mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 11:44:28 +00:00
Auto merge of #30759 - Manishearth:attr-tls, r=alexcrichton
fixes #30756 r? @Gankro
This commit is contained in:
commit
c007e4a010
@ -92,7 +92,7 @@ pub struct LocalKey<T: 'static> {
|
||||
// trivially devirtualizable by LLVM because the value of `inner` never
|
||||
// changes and the constant should be readonly within a crate. This mainly
|
||||
// only runs into problems when TLS statics are exported across crates.
|
||||
inner: unsafe fn() -> Option<&'static UnsafeCell<Option<T>>>,
|
||||
inner: fn() -> Option<&'static UnsafeCell<Option<T>>>,
|
||||
|
||||
// initialization routine to invoke to create a value
|
||||
init: fn() -> T,
|
||||
@ -126,7 +126,7 @@ macro_rules! __thread_local_inner {
|
||||
($t:ty, $init:expr) => {{
|
||||
fn __init() -> $t { $init }
|
||||
|
||||
unsafe fn __getit() -> $crate::option::Option<
|
||||
fn __getit() -> $crate::option::Option<
|
||||
&'static $crate::cell::UnsafeCell<
|
||||
$crate::option::Option<$t>>>
|
||||
{
|
||||
@ -183,7 +183,7 @@ impl<T: 'static> LocalKey<T> {
|
||||
#[unstable(feature = "thread_local_internals",
|
||||
reason = "recently added to create a key",
|
||||
issue = "0")]
|
||||
pub const fn new(inner: unsafe fn() -> Option<&'static UnsafeCell<Option<T>>>,
|
||||
pub const fn new(inner: fn() -> Option<&'static UnsafeCell<Option<T>>>,
|
||||
init: fn() -> T) -> LocalKey<T> {
|
||||
LocalKey {
|
||||
inner: inner,
|
||||
@ -303,11 +303,13 @@ pub mod elf {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||
unsafe {
|
||||
if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
|
||||
return None
|
||||
}
|
||||
self.register_dtor();
|
||||
}
|
||||
Some(&self.inner)
|
||||
}
|
||||
|
||||
@ -452,7 +454,8 @@ pub mod os {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||
unsafe {
|
||||
let ptr = self.os.get() as *mut Value<T>;
|
||||
if !ptr.is_null() {
|
||||
if ptr as usize == 1 {
|
||||
@ -472,6 +475,7 @@ pub mod os {
|
||||
Some(&(*ptr).value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe extern fn destroy_value<T: 'static>(ptr: *mut u8) {
|
||||
// The OS TLS ensures that this key contains a NULL value when this
|
||||
|
16
src/test/run-pass/issue-30756.rs
Normal file
16
src/test/run-pass/issue-30756.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
|
||||
thread_local!(static FOO: u8 = 1);
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue
Block a user