This is an automated email from the ASF dual-hosted git repository.

rduan pushed a commit to branch v1.1.4-testing
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git


The following commit(s) were added to refs/heads/v1.1.4-testing by this push:
     new 6633552  fix: const-initialized thread locals
6633552 is described below

commit 66335521c2e959b5d70120e457a14988d4ae2f49
Author: volcano0dr <[email protected]>
AuthorDate: Fri Oct 8 19:27:10 2021 +0800

    fix: const-initialized thread locals
    
    Signed-off-by: volcano0dr <[email protected]>
---
 sgx_tstd/src/thread/local.rs | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/sgx_tstd/src/thread/local.rs b/sgx_tstd/src/thread/local.rs
index a3440bd..aa009d0 100644
--- a/sgx_tstd/src/thread/local.rs
+++ b/sgx_tstd/src/thread/local.rs
@@ -157,9 +157,9 @@ macro_rules! __thread_local_inner {
                 static mut VAL: $t = $init;
                 Ok(&VAL)
             } else {
-                Err(AccessError {
-                    msg: "If TLS data needs to be destructed, TCS policy must 
be bound.",
-                })
+                Err($crate::thread::AccessError::new(
+                    "If TLS data needs to be destructed, TCS policy must be 
bound."
+                ))
             }
         }
 
@@ -205,6 +205,12 @@ pub struct AccessError {
     msg: &'static str,
 }
 
+impl AccessError {
+    pub fn new(msg: &'static str) -> Self {
+        Self { msg }
+    }
+}
+
 impl fmt::Display for AccessError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Display::fmt(self.msg, f)
@@ -368,9 +374,9 @@ pub mod statik {
                 };
                 Ok(value)
             } else {
-                Err(AccessError {
-                    msg: "If TLS data needs to be destructed, TCS policy must 
be bound.",
-                })
+                Err(AccessError::new(
+                    "If TLS data needs to be destructed, TCS policy must be 
bound."
+                ))
             }
         }
     }
@@ -470,9 +476,9 @@ pub mod fast {
         #[inline(never)]
         unsafe fn try_initialize<F: FnOnce() -> T>(&self, init: F) -> 
Result<&'static T, AccessError> {
             if mem::needs_drop::<T>() && thread::thread_policy() == 
SgxThreadPolicy::Unbound {
-                return Err(AccessError {
-                    msg: "If TLS data needs to be destructed, TCS policy must 
be bound.",
-                });
+                return Err(AccessError::new(
+                    "If TLS data needs to be destructed, TCS policy must be 
bound."
+                ));
             }
 
             if !super::pthread_info_tls.m_pthread.is_null() {
@@ -489,9 +495,7 @@ pub mod fast {
                 // SAFETY: See comment above (his function doc).
                     Ok(self.inner.initialize(init))
                 } else {
-                    Err(AccessError {
-                        msg: "Failed to register destructor.",
-                    })
+                    Err(AccessError::new("Failed to register destructor."))
                 }
             } else {
                 Ok(self.inner.initialize(init))
@@ -604,9 +608,7 @@ pub mod os {
             let ptr = self.os.get() as *mut Value<T>;
             if ptr as usize == 1 {
                 // destructor is running
-                return Err(AccessError {
-                    msg: "Destructor is running.",
-                });
+                return Err(AccessError::new("Destructor is running."));
             }
 
             let ptr = if ptr.is_null() {

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to