Skip to content

Commit d801db9

Browse files
windows get macro'd out
1 parent 98c503b commit d801db9

File tree

1 file changed

+8
-81
lines changed

1 file changed

+8
-81
lines changed

rubicon/src/lib.rs

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ macro_rules! compatibility_check {
323323
};
324324
}
325325

326-
#[cfg(feature = "import-globals")]
326+
#[cfg(all(unix, feature = "import-globals"))]
327327
#[macro_export]
328328
macro_rules! compatibility_check {
329329
($($feature:tt)*) => {
@@ -336,7 +336,6 @@ macro_rules! compatibility_check {
336336
}
337337

338338

339-
#[cfg(unix)]
340339
fn get_shared_object_name() -> Option<String> {
341340
use $crate::libc::{c_void, Dl_info};
342341
use std::ffi::CStr;
@@ -356,83 +355,6 @@ macro_rules! compatibility_check {
356355
None
357356
}
358357

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-
436358
struct AnsiEscape<D: std::fmt::Display>(u64, D);
437359

438360
impl<D: std::fmt::Display> std::fmt::Display for AnsiEscape<D> {
@@ -486,7 +408,6 @@ macro_rules! compatibility_check {
486408
len
487409
}
488410

489-
#[cfg(unix)]
490411
#[ctor]
491412
fn check_compatibility() {
492413
eprintln!("Entering check_compatibility function");
@@ -682,8 +603,14 @@ macro_rules! compatibility_check {
682603
eprintln!("Panicking with error message");
683604
panic!("{}", error_message);
684605
}
606+
};
607+
}
685608

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
687614
};
688615
}
689616

0 commit comments

Comments
 (0)