Avoid changing the error variant name for now - Should be done in the next breaking change

This commit is contained in:
NightRa
2020-04-15 19:05:09 +03:00
parent c884c279ff
commit 55d238c8c1
2 changed files with 12 additions and 12 deletions
+7 -7
View File
@@ -31,10 +31,10 @@ pub enum Error {
DlClose { desc: DlDescription },
/// The `dlclose` call failed and system did not report an error.
DlCloseUnknown,
/// The `LoadLibraryExW` call failed.
LoadLibraryExW { source: WindowsError },
/// The `LoadLibraryExW` call failed and system did not report an error.
LoadLibraryExWUnknown,
/// The `LoadLibraryW` call failed.
LoadLibraryW { source: WindowsError },
/// The `LoadLibraryW` call failed and system did not report an error.
LoadLibraryWUnknown,
/// The `GetProcAddress` call failed.
GetProcAddress { source: WindowsError },
/// The `GetProcAddressUnknown` call failed and system did not report an error.
@@ -57,7 +57,7 @@ impl std::error::Error for Error {
match *self {
CreateCString { ref source } => Some(source),
CreateCStringWithTrailing { ref source } => Some(source),
LoadLibraryExW { ref source } => Some(&source.0),
LoadLibraryW { ref source } => Some(&source.0),
GetProcAddress { ref source } => Some(&source.0),
FreeLibrary { ref source } => Some(&source.0),
_ => None,
@@ -75,8 +75,8 @@ impl std::fmt::Display for Error {
DlSymUnknown => write!(f, "dlsym failed, but system did not report the error"),
DlClose { ref desc } => write!(f, "{}", desc.0.to_string_lossy()),
DlCloseUnknown => write!(f, "dlclose failed, but system did not report the error"),
LoadLibraryExW { .. } => write!(f, "LoadLibraryW failed"),
LoadLibraryExWUnknown =>
LoadLibraryW { .. } => write!(f, "LoadLibraryW failed"),
LoadLibraryWUnknown =>
write!(f, "LoadLibraryW failed, but system did not report the error"),
GetProcAddress { .. } => write!(f, "GetProcAddress failed"),
GetProcAddressUnknown =>
+5 -5
View File
@@ -33,7 +33,7 @@ unsafe impl Sync for Library {}
impl Library {
/// Find and load a shared library (module).
///
/// Corresponds to `LoadLibraryExW(filename, reserved: NULL, flags: 0)` which is equivalent to `LoadLibraryW(filename)`
/// Corresponds to `LoadLibraryW(filename, reserved: NULL, flags: 0)` which is equivalent to `LoadLibraryW(filename)`
#[inline]
pub fn new<P: AsRef<OsStr>>(filename: P) -> Result<Library, crate::Error> {
Library::load_with_flags(filename, 0)
@@ -44,12 +44,12 @@ impl Library {
/// Locations where library is searched for is platform specific and cant be adjusted
/// portably.
///
/// Corresponds to `LoadLibraryExW(filename, reserved: NULL, flags)`.
/// Corresponds to `LoadLibraryW(filename, reserved: NULL, flags)`.
pub fn load_with_flags<P: AsRef<OsStr>>(filename: P, flags: DWORD) -> Result<Library, crate::Error> {
let wide_filename: Vec<u16> = filename.as_ref().encode_wide().chain(Some(0)).collect();
let _guard = ErrorModeGuard::new();
let ret = with_get_last_error(|source| crate::Error::LoadLibraryExW { source }, || {
let ret = with_get_last_error(|source| crate::Error::LoadLibraryW { source }, || {
// Make sure no winapi calls as a result of drop happen inside this closure, because
// otherwise that might change the return value of the GetLastError.
let handle = unsafe { libloaderapi::LoadLibraryExW(wide_filename.as_ptr(), std::ptr::null_mut(), flags) };
@@ -58,9 +58,9 @@ impl Library {
} else {
Some(Library(handle))
}
}).map_err(|e| e.unwrap_or(crate::Error::LoadLibraryExWUnknown));
}).map_err(|e| e.unwrap_or(crate::Error::LoadLibraryWUnknown));
drop(wide_filename); // Drop wide_filename here to ensure it doesnt get moved and dropped
// inside the closure by mistake. See comment inside the closure.
// inside the closure by mistake. See comment inside the closure.
ret
}