From cf3717575937845f1af33d887452f2aee3e4f78f Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Sun, 25 Apr 2021 06:26:47 -0700 Subject: [PATCH 1/4] Fix get_dylib_path() on Windows GetModuleHandleExW returns 0 on failure --- src/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows.rs b/src/windows.rs index f2b13eb..11b1c6e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -49,7 +49,7 @@ pub(crate) fn get_dylib_path() -> Option { | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, get_dylib_path as *const _, &mut handle_module, - ) != 0 { + ) == 0 { None } else { let ret = From 99afcaf9546db57fa07dfb58d9f19b09aac234be Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Sun, 25 Apr 2021 06:33:31 -0700 Subject: [PATCH 2/4] Start with MAX_PATH-sized buffers on Windows to avoid most reallocations --- src/windows.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 11b1c6e..d9b7d1e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -2,7 +2,7 @@ use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; -use winapi::shared::minwindef::DWORD; +use winapi::shared::minwindef::{DWORD, MAX_PATH}; use winapi::um::{ errhandlingapi::GetLastError, libloaderapi::{ @@ -36,7 +36,7 @@ pub(crate) fn get_executable_path() -> Option { } } - get_executable_path(256) + get_executable_path(MAX_PATH) } pub(crate) fn get_dylib_path() -> Option { @@ -74,5 +74,5 @@ pub(crate) fn get_dylib_path() -> Option { } } - get_dylib_path(256) + get_dylib_path(MAX_PATH) } From 064acfa3e2b1450506a6b0e0b4674f7f9768ee61 Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Sun, 25 Apr 2021 06:37:03 -0700 Subject: [PATCH 3/4] Reformat source according to rustfmt --- src/windows.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index d9b7d1e..e29997b 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -3,14 +3,14 @@ use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; use winapi::shared::minwindef::{DWORD, MAX_PATH}; +use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::{ errhandlingapi::GetLastError, libloaderapi::{ - GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - } + }, }; -use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; pub(crate) fn get_executable_path() -> Option { fn get_executable_path(len: usize) -> Option { @@ -49,7 +49,8 @@ pub(crate) fn get_dylib_path() -> Option { | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, get_dylib_path as *const _, &mut handle_module, - ) == 0 { + ) == 0 + { None } else { let ret = From ca85588a9e507413f7d0a40153f19aff6ac7e204 Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Sun, 25 Apr 2021 06:37:30 -0700 Subject: [PATCH 4/4] Bump crate version --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa2057f..30b9b78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "process_path" -version = "0.1.3" +version = "0.1.4" authors = ["Wesley Wiser ", "Moritz Moeller "] license = "MIT/Apache-2.0" repository = "https://github.com/wesleywiser/process_path" diff --git a/README.md b/README.md index f533a46..ffc8f8e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ library in the file system. Add this to your `Cargo.toml`: ```toml [dependencies] -process_path = "0.1.3" +process_path = "0.1.4" ``` and this to your crate root: ```rust