@@ -111,6 +111,8 @@ macro_rules! dbghelp {
111
111
#[ allow( dead_code) ]
112
112
impl Init {
113
113
$( pub fn $name( & self ) -> $name {
114
+ // FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
115
+ #[ allow( static_mut_refs) ]
114
116
unsafe {
115
117
DBGHELP . $name( ) . unwrap( )
116
118
}
@@ -318,24 +320,26 @@ pub fn init() -> Result<Init, ()> {
318
320
// functions in it, and that's detailed more below. We only do this
319
321
// once, though, so we've got a global boolean indicating whether we're
320
322
// done yet or not.
323
+ // FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
324
+ #[ allow( static_mut_refs) ]
321
325
DBGHELP . ensure_open ( ) ?;
322
326
323
327
static mut INITIALIZED : bool = false ;
324
328
if !INITIALIZED {
325
- set_optional_options ( ) ;
329
+ set_optional_options ( ret . dbghelp ( ) ) ;
326
330
INITIALIZED = true ;
327
331
}
328
332
Ok ( ret)
329
333
}
330
334
}
331
- fn set_optional_options ( ) -> Option < ( ) > {
335
+ unsafe fn set_optional_options ( dbghelp : * mut Dbghelp ) -> Option < ( ) > {
332
336
unsafe {
333
- let orig = DBGHELP . SymGetOptions ( ) ?( ) ;
337
+ let orig = ( * dbghelp ) . SymGetOptions ( ) ?( ) ;
334
338
335
339
// Ensure that the `SYMOPT_DEFERRED_LOADS` flag is set, because
336
340
// according to MSVC's own docs about this: "This is the fastest, most
337
341
// 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 ) ;
339
343
340
344
// Actually initialize symbols with MSVC. Note that this can fail, but we
341
345
// 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<()> {
349
353
// the time, but now that it's using this crate it means that someone will
350
354
// get to initialization first and the other will pick up that
351
355
// initialization.
352
- DBGHELP . SymInitializeW ( ) ?( GetCurrentProcess ( ) , ptr:: null_mut ( ) , TRUE ) ;
356
+ ( * dbghelp ) . SymInitializeW ( ) ?( GetCurrentProcess ( ) , ptr:: null_mut ( ) , TRUE ) ;
353
357
354
358
// The default search path for dbghelp will only look in the current working
355
359
// directory and (possibly) `_NT_SYMBOL_PATH` and `_NT_ALT_SYMBOL_PATH`.
@@ -363,7 +367,7 @@ fn set_optional_options() -> Option<()> {
363
367
search_path_buf. resize ( 1024 , 0 ) ;
364
368
365
369
// Prefill the buffer with the current search path.
366
- if DBGHELP . SymGetSearchPathW ( ) ?(
370
+ if ( * dbghelp ) . SymGetSearchPathW ( ) ?(
367
371
GetCurrentProcess ( ) ,
368
372
search_path_buf. as_mut_ptr ( ) ,
369
373
search_path_buf. len ( ) as _ ,
@@ -383,7 +387,7 @@ fn set_optional_options() -> Option<()> {
383
387
let mut search_path = SearchPath :: new ( search_path_buf) ;
384
388
385
389
// Update the search path to include the directory of the executable and each DLL.
386
- DBGHELP . EnumerateLoadedModulesW64 ( ) ?(
390
+ ( * dbghelp ) . EnumerateLoadedModulesW64 ( ) ?(
387
391
GetCurrentProcess ( ) ,
388
392
Some ( enum_loaded_modules_callback) ,
389
393
( ( & mut search_path) as * mut SearchPath ) as * mut c_void ,
@@ -392,7 +396,7 @@ fn set_optional_options() -> Option<()> {
392
396
let new_search_path = search_path. finalize ( ) ;
393
397
394
398
// Set the new search path.
395
- DBGHELP . SymSetSearchPathW ( ) ?( GetCurrentProcess ( ) , new_search_path. as_ptr ( ) ) ;
399
+ ( * dbghelp ) . SymSetSearchPathW ( ) ?( GetCurrentProcess ( ) , new_search_path. as_ptr ( ) ) ;
396
400
}
397
401
Some ( ( ) )
398
402
}
0 commit comments