Prevent cyclic locks of alloc_map

This commit is contained in:
Oliver Scherer 2019-06-03 17:49:14 +02:00
parent 4b6f3868b3
commit 21b1bd69b0

View File

@ -453,8 +453,11 @@ pub fn get_size_and_align(
if let Ok(alloc) = self.get(id) {
return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align));
}
// can't do this in the match argument, we may get cycle errors since the lock would get
// dropped after the match.
let alloc = self.tcx.alloc_map.lock().get(id);
// Could also be a fn ptr or extern static
match self.tcx.alloc_map.lock().get(id) {
match alloc {
Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())),
// `self.get` would also work, but can cause cycles if a static refers to itself
Some(GlobalAlloc::Static(did)) => {