@@ -323,7 +323,7 @@ macro_rules! compatibility_check {
323
323
} ;
324
324
}
325
325
326
- #[ cfg( feature = "import-globals" ) ]
326
+ #[ cfg( all ( unix , feature = "import-globals" ) ) ]
327
327
#[ macro_export]
328
328
macro_rules! compatibility_check {
329
329
( $( $feature: tt) * ) => {
@@ -336,7 +336,6 @@ macro_rules! compatibility_check {
336
336
}
337
337
338
338
339
- #[ cfg( unix) ]
340
339
fn get_shared_object_name( ) -> Option <String > {
341
340
use $crate:: libc:: { c_void, Dl_info } ;
342
341
use std:: ffi:: CStr ;
@@ -356,83 +355,6 @@ macro_rules! compatibility_check {
356
355
None
357
356
}
358
357
359
- #[ cfg( windows) ]
360
- fn get_shared_object_name( ) -> Option <String > {
361
- eprintln!( "Entering get_shared_object_name function" ) ;
362
- use std:: mem:: MaybeUninit ;
363
- use std:: ptr;
364
- use std:: ffi:: OsString ;
365
- use std:: os:: windows:: ffi:: OsStringExt ;
366
-
367
- #[ allow( non_snake_case) ]
368
- #[ repr( C ) ]
369
- struct MODULEINFO {
370
- lpBaseOfDll: * mut std:: ffi:: c_void,
371
- SizeOfImage : u32 ,
372
- EntryPoint : * mut std:: ffi:: c_void,
373
- }
374
-
375
- type HANDLE = * mut std:: ffi:: c_void;
376
- type HMODULE = HANDLE ;
377
- type DWORD = u32 ;
378
- type BOOL = i32 ;
379
- type LPCWSTR = * const u16 ;
380
- type LPWSTR = * mut u16 ;
381
-
382
- const MAX_PATH : u32 = 260 ;
383
- const ERROR_INSUFFICIENT_BUFFER : u32 = 122 ;
384
-
385
- extern "system" {
386
- fn GetModuleHandleW ( lpModuleName: LPCWSTR ) -> HMODULE ;
387
- fn GetModuleFileNameW ( hModule: HMODULE , lpFilename: LPWSTR , nSize: DWORD ) -> DWORD ;
388
- fn GetLastError ( ) -> DWORD ;
389
- }
390
-
391
- unsafe {
392
- eprintln!( "Calling GetModuleHandleW" ) ;
393
- let module = GetModuleHandleW ( ptr:: null( ) ) ;
394
- if module. is_null( ) {
395
- eprintln!( "GetModuleHandleW returned null" ) ;
396
- return None ;
397
- }
398
-
399
- let mut buffer_size = MAX_PATH ;
400
- loop {
401
- eprintln!( "Entering loop with buffer_size: {}" , buffer_size) ;
402
- let mut buffer = Vec :: <u16 >:: with_capacity( buffer_size as usize ) ;
403
- eprintln!( "Calling GetModuleFileNameW" ) ;
404
- let result = GetModuleFileNameW ( module, buffer. as_mut_ptr( ) , buffer_size) ;
405
-
406
- if result == 0 {
407
- eprintln!( "GetModuleFileNameW returned 0" ) ;
408
- return None ;
409
- }
410
-
411
- if result < buffer_size {
412
- eprintln!( "GetModuleFileNameW succeeded with result: {}" , result) ;
413
- buffer. set_len( result as usize ) ;
414
- let os_string = OsString :: from_wide( & buffer) ;
415
- let string = os_string. to_string_lossy( ) . into_owned( ) ;
416
- eprintln!( "Returning string: {}" , string) ;
417
- return Some ( string) ;
418
- }
419
-
420
- if GetLastError ( ) == ERROR_INSUFFICIENT_BUFFER {
421
- eprintln!( "Buffer insufficient, doubling size" ) ;
422
- buffer_size *= 2 ;
423
- } else {
424
- eprintln!( "Unexpected error: {}" , GetLastError ( ) ) ;
425
- return None ;
426
- }
427
- }
428
- }
429
- }
430
-
431
- #[ cfg( not( any( unix, windows) ) ) ]
432
- fn get_shared_object_name( ) -> Option <String > {
433
- None
434
- }
435
-
436
358
struct AnsiEscape <D : std:: fmt:: Display >( u64 , D ) ;
437
359
438
360
impl <D : std:: fmt:: Display > std:: fmt:: Display for AnsiEscape <D > {
@@ -486,7 +408,6 @@ macro_rules! compatibility_check {
486
408
len
487
409
}
488
410
489
- #[ cfg( unix) ]
490
411
#[ ctor]
491
412
fn check_compatibility( ) {
492
413
eprintln!( "Entering check_compatibility function" ) ;
@@ -682,8 +603,14 @@ macro_rules! compatibility_check {
682
603
eprintln!( "Panicking with error message" ) ;
683
604
panic!( "{}" , error_message) ;
684
605
}
606
+ } ;
607
+ }
685
608
686
- /// compatibility checks are not supported on Windows
609
+ #[ cfg( all( not( unix) , feature = "import-globals" ) ) ]
610
+ #[ macro_export]
611
+ macro_rules! compatibility_check {
612
+ ( $( $feature: tt) * ) => {
613
+ /// compatibility checks are only supported on unix-like system
687
614
} ;
688
615
}
689
616
0 commit comments