Skip to content

Commit 9737fc3

Browse files
committed
Allow some static_mut_refs
1 parent 26ab4af commit 9737fc3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/dbghelp.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ macro_rules! dbghelp {
111111
#[allow(dead_code)]
112112
impl Init {
113113
$(pub fn $name(&self) -> $name {
114+
// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
115+
#[allow(static_mut_refs)]
114116
unsafe {
115117
DBGHELP.$name().unwrap()
116118
}
@@ -318,24 +320,26 @@ pub fn init() -> Result<Init, ()> {
318320
// functions in it, and that's detailed more below. We only do this
319321
// once, though, so we've got a global boolean indicating whether we're
320322
// done yet or not.
323+
// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
324+
#[allow(static_mut_refs)]
321325
DBGHELP.ensure_open()?;
322326

323327
static mut INITIALIZED: bool = false;
324328
if !INITIALIZED {
325-
set_optional_options();
329+
set_optional_options(ret.dbghelp());
326330
INITIALIZED = true;
327331
}
328332
Ok(ret)
329333
}
330334
}
331-
fn set_optional_options() -> Option<()> {
335+
unsafe fn set_optional_options(dbghelp: *mut Dbghelp) -> Option<()> {
332336
unsafe {
333-
let orig = DBGHELP.SymGetOptions()?();
337+
let orig = (*dbghelp).SymGetOptions()?();
334338

335339
// Ensure that the `SYMOPT_DEFERRED_LOADS` flag is set, because
336340
// according to MSVC's own docs about this: "This is the fastest, most
337341
// efficient way to use the symbol handler.", so let's do that!
338-
DBGHELP.SymSetOptions()?(orig | SYMOPT_DEFERRED_LOADS);
342+
(*dbghelp).SymSetOptions()?(orig | SYMOPT_DEFERRED_LOADS);
339343

340344
// Actually initialize symbols with MSVC. Note that this can fail, but we
341345
// ignore it. There's not a ton of prior art for this per se, but LLVM
@@ -349,7 +353,7 @@ fn set_optional_options() -> Option<()> {
349353
// the time, but now that it's using this crate it means that someone will
350354
// get to initialization first and the other will pick up that
351355
// initialization.
352-
DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE);
356+
(*dbghelp).SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE);
353357

354358
// The default search path for dbghelp will only look in the current working
355359
// directory and (possibly) `_NT_SYMBOL_PATH` and `_NT_ALT_SYMBOL_PATH`.
@@ -363,7 +367,7 @@ fn set_optional_options() -> Option<()> {
363367
search_path_buf.resize(1024, 0);
364368

365369
// Prefill the buffer with the current search path.
366-
if DBGHELP.SymGetSearchPathW()?(
370+
if (*dbghelp).SymGetSearchPathW()?(
367371
GetCurrentProcess(),
368372
search_path_buf.as_mut_ptr(),
369373
search_path_buf.len() as _,
@@ -383,7 +387,7 @@ fn set_optional_options() -> Option<()> {
383387
let mut search_path = SearchPath::new(search_path_buf);
384388

385389
// Update the search path to include the directory of the executable and each DLL.
386-
DBGHELP.EnumerateLoadedModulesW64()?(
390+
(*dbghelp).EnumerateLoadedModulesW64()?(
387391
GetCurrentProcess(),
388392
Some(enum_loaded_modules_callback),
389393
((&mut search_path) as *mut SearchPath) as *mut c_void,
@@ -392,7 +396,7 @@ fn set_optional_options() -> Option<()> {
392396
let new_search_path = search_path.finalize();
393397

394398
// Set the new search path.
395-
DBGHELP.SymSetSearchPathW()?(GetCurrentProcess(), new_search_path.as_ptr());
399+
(*dbghelp).SymSetSearchPathW()?(GetCurrentProcess(), new_search_path.as_ptr());
396400
}
397401
Some(())
398402
}

src/symbolize/gimli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ impl Cache {
363363
// never happen, and symbolicating backtraces would be ssssllllooooowwww.
364364
static mut MAPPINGS_CACHE: Option<Cache> = None;
365365

366+
// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
367+
#[allow(static_mut_refs)]
366368
f(MAPPINGS_CACHE.get_or_insert_with(Cache::new))
367369
}
368370

0 commit comments

Comments
 (0)