From 2acf0afbc8b4e2147483fe51e040b83e35df0d7b Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 11 Apr 2018 12:34:38 +0200 Subject: [PATCH 1/2] parity uses winapi 0.3.4 --- Cargo.lock | 3 +-- Cargo.toml | 3 +-- parity/main.rs | 7 +++---- parity/url.rs | 21 ++++----------------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5c7963f64c..ffd53e722a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1995,8 +1995,7 @@ dependencies = [ "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 291e157cc40..9fe110a77f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ app_dirs = "1.2.1" futures = "0.1" futures-cpupool = "0.1" fdlimit = "0.1" -ws2_32-sys = "0.2" ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" } ethcore = { path = "ethcore" } @@ -85,7 +84,7 @@ tempdir = "0.3" fake-fetch = { path = "util/fake-fetch" } [target.'cfg(windows)'.dependencies] -winapi = "0.2" +winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] } [target.'cfg(not(windows))'.dependencies] daemonize = { git = "https://github.com/paritytech/daemonize" } diff --git a/parity/main.rs b/parity/main.rs index 7179996bf58..3e4fa263fa9 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -95,7 +95,6 @@ extern crate parity_dapps; #[macro_use] extern crate pretty_assertions; -#[cfg(windows)] extern crate ws2_32; #[cfg(windows)] extern crate winapi; #[cfg(test)] @@ -238,7 +237,7 @@ fn global_cleanup() { // The loop is required because of internal refernce counter for winsock dll. We don't know how many crates we use do // initialize it. There's at least 2 now. for _ in 0.. 10 { - unsafe { ::ws2_32::WSACleanup(); } + unsafe { ::winapi::um::winsock2::WSACleanup(); } } } @@ -250,8 +249,8 @@ fn global_init() { // When restarting in the same process this reinits windows sockets. unsafe { const WS_VERSION: u16 = 0x202; - let mut wsdata: ::winapi::winsock2::WSADATA = ::std::mem::zeroed(); - ::ws2_32::WSAStartup(WS_VERSION, &mut wsdata); + let mut wsdata: ::winapi::um::winsock2::WSADATA = ::std::mem::zeroed(); + ::winapi::um::winsock2::WSAStartup(WS_VERSION, &mut wsdata); } } diff --git a/parity/url.rs b/parity/url.rs index fd64e46eca8..4189ae24184 100644 --- a/parity/url.rs +++ b/parity/url.rs @@ -16,33 +16,20 @@ //! Cross-platform open url in default browser -#[cfg(windows)] -mod shell { - extern crate winapi; - - use self::winapi::*; - extern "system" { - pub fn ShellExecuteA( - hwnd: HWND, lpOperation: LPCSTR, lpFile: LPCSTR, lpParameters: LPCSTR, lpDirectory: LPCSTR, - nShowCmd: c_int - ) -> HINSTANCE; - } - - pub use self::winapi::SW_SHOWNORMAL as Normal; -} - #[cfg(windows)] pub fn open(url: &str) { use std::ffi::CString; use std::ptr; + use winapi::um::shellapi::ShellExecuteA; + use winapi::um::winuser::SW_SHOWNORMAL as Normal; unsafe { - shell::ShellExecuteA(ptr::null_mut(), + ShellExecuteA(ptr::null_mut(), CString::new("open").unwrap().as_ptr(), CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(), ptr::null(), ptr::null(), - shell::Normal); + Normal); } } From 8a2f467370557282f614aabeaa5e974a954458ca Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 11 Apr 2018 14:19:17 +0200 Subject: [PATCH 2/2] remove redundant unsafe --- parity/url.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/parity/url.rs b/parity/url.rs index 4189ae24184..9b8959f01db 100644 --- a/parity/url.rs +++ b/parity/url.rs @@ -23,14 +23,12 @@ pub fn open(url: &str) { use winapi::um::shellapi::ShellExecuteA; use winapi::um::winuser::SW_SHOWNORMAL as Normal; - unsafe { - ShellExecuteA(ptr::null_mut(), - CString::new("open").unwrap().as_ptr(), - CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(), - ptr::null(), - ptr::null(), - Normal); - } + ShellExecuteA(ptr::null_mut(), + CString::new("open").unwrap().as_ptr(), + CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(), + ptr::null(), + ptr::null(), + Normal); } #[cfg(any(target_os="macos", target_os="freebsd"))]