difftreelog
fix workaround TLS issues on process termination
in: master
1 file changed
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth797980impl Drop for IStr {80impl Drop for IStr {81 fn drop(&mut self) {81 fn drop(&mut self) {82 #[cold]83 #[inline(never)]84 fn unpool(inner: &Inner) {85 // May fail on program termination86 let res = POOL.try_with(|pool| pool.borrow_mut().remove(inner));87 if res.is_ok() {88 debug_assert_eq!(Inner::strong_count(inner), 1);89 }90 }91 // First reference - current object, second - POOL92 if Inner::strong_count(&self.0) <= 2 {82 maybe_unpool(&self.0)93 unpool(&self.0);94 }95 }83 }96}84}9785161 }149 }162}150}163151164impl Drop for IBytes {152impl Drop for IBytes {153 fn drop(&mut self) {154 maybe_unpool(&self.0)155 }156}157165 fn drop(&mut self) {158fn maybe_unpool(inner: &Inner) {166 #[cold]159 #[cold]167 #[inline(never)]160 #[inline(never)]168 fn unpool(inner: &Inner) {161 fn unpool(inner: &Inner) {169 // May fail on program termination162 // May fail on program termination170 let res = POOL.try_with(|pool| pool.borrow_mut().remove(inner));163 let _ = POOL.try_with(|pool| {171 if res.is_ok() {164 let mut pool = pool.borrow_mut();172 debug_assert_eq!(Inner::strong_count(inner), 1);165173 }166 if pool.remove(inner).is_none() {167 // On some platforms (i.e i686-windows), try_with will not fail after TLS168 // destructor is called, but instead re-initialize the TLS with the empty pool.169 // Allow non-pooled Drop in this case.170 // https://github.com/CertainLach/jrsonnet/issues/98#issuecomment-1591624016171 //172 // However, if pool is not empty, most likely this is issue #113, and then I don't173 // have any explainations for now.174 assert!(pool.is_empty(), "received an unpooled string not during the program termination, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!");175 }176 });174 }177 }175 // First reference - current object, second - POOL178 // First reference - current object, second - POOL176 if Inner::strong_count(&self.0) <= 2 {179 if Inner::strong_count(&inner) <= 2 {177 unpool(&self.0);180 unpool(&inner);178 }181 }179 }182}180}181183182impl fmt::Debug for IBytes {184impl fmt::Debug for IBytes {183 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {185 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {