From 89429f26c032303d292d65d74298c635d843b82f Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 12 May 2023 18:09:22 +0200 Subject: [PATCH] Follow POSIX by allowing NULL pthread_key_t dtors. --- src/header/pthread/tls.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/header/pthread/tls.rs b/src/header/pthread/tls.rs index 6a064f97..57c7c354 100644 --- a/src/header/pthread/tls.rs +++ b/src/header/pthread/tls.rs @@ -30,7 +30,7 @@ pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void data } #[no_mangle] -pub unsafe extern "C" fn pthread_key_create(key_ptr: *mut pthread_key_t, destructor: extern "C" fn(value: *mut c_void)) -> c_int { +pub unsafe extern "C" fn pthread_key_create(key_ptr: *mut pthread_key_t, destructor: Option<extern "C" fn(value: *mut c_void)>) -> c_int { let key = NEXTKEY.get(); NEXTKEY.set(key + 1); //println!("pthread_key_create new key {:#0x}, dtor {:p}", key, destructor); @@ -82,7 +82,7 @@ pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c static KEYS: Mutex<BTreeMap<pthread_key_t, Dtor>> = Mutex::new(BTreeMap::new()); struct Dtor { - destructor: extern "C" fn(value: *mut c_void) + destructor: Option<extern "C" fn(value: *mut c_void)>, } #[thread_local] @@ -97,8 +97,8 @@ static NEXTKEY: Cell<pthread_key_t> = Cell::new(1); pub(crate) unsafe fn run_all_destructors() { for (key, Record { data }) in VALUES.take() { - let Some(&Dtor { destructor }) = KEYS.lock().get(&key) else { continue }; + let Some(&Dtor { destructor: Some(dtor) }) = KEYS.lock().get(&key) else { continue }; - destructor(data); + dtor(data); } } -- GitLab