parity uses winapi 0.3.4 (#8366)

* parity uses winapi 0.3.4

* remove redundant unsafe
This commit is contained in:
Marek Kotewicz
2018-04-11 15:22:48 +02:00
committed by GitHub
parent 0a9114203b
commit 1356d6d8d5
4 changed files with 13 additions and 31 deletions

View File

@@ -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);
}
}

View File

@@ -16,34 +16,19 @@
//! 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(),
CString::new("open").unwrap().as_ptr(),
CString::new(url.to_owned().replace("\n", "%0A")).unwrap().as_ptr(),
ptr::null(),
ptr::null(),
shell::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"))]