Updated std::dynamic_lib to use std::path.
This commit is contained in:
@@ -18,10 +18,6 @@ use std::borrow::ToOwned;
|
|||||||
use std::dynamic_lib::DynamicLibrary;
|
use std::dynamic_lib::DynamicLibrary;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
use std::old_path;
|
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::codemap::{Span, COMMAND_LINE_SP};
|
use syntax::codemap::{Span, COMMAND_LINE_SP};
|
||||||
@@ -110,7 +106,6 @@ impl<'a> PluginLoader<'a> {
|
|||||||
symbol: String) -> PluginRegistrarFun {
|
symbol: String) -> PluginRegistrarFun {
|
||||||
// Make sure the path contains a / or the linker will search for it.
|
// Make sure the path contains a / or the linker will search for it.
|
||||||
let path = env::current_dir().unwrap().join(&path);
|
let path = env::current_dir().unwrap().join(&path);
|
||||||
let path = old_path::Path::new(path.to_str().unwrap());
|
|
||||||
|
|
||||||
let lib = match DynamicLibrary::open(Some(&path)) {
|
let lib = match DynamicLibrary::open(Some(&path)) {
|
||||||
Ok(lib) => lib,
|
Ok(lib) => lib,
|
||||||
|
|||||||
@@ -14,16 +14,15 @@
|
|||||||
|
|
||||||
#![unstable(feature = "std_misc")]
|
#![unstable(feature = "std_misc")]
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
#![allow(deprecated)] // will be addressed by #23197
|
|
||||||
|
|
||||||
use prelude::v1::*;
|
use prelude::v1::*;
|
||||||
|
|
||||||
use env;
|
use env;
|
||||||
use ffi::CString;
|
use ffi::{AsOsStr, CString, OsString};
|
||||||
use mem;
|
use mem;
|
||||||
use old_path::{Path, GenericPath};
|
use path::{Path, PathBuf};
|
||||||
use os;
|
#[cfg(not(target_os = "android"))] use os;
|
||||||
use str;
|
#[cfg(not(target_os = "android"))] use str;
|
||||||
|
|
||||||
pub struct DynamicLibrary {
|
pub struct DynamicLibrary {
|
||||||
handle: *mut u8
|
handle: *mut u8
|
||||||
@@ -54,7 +53,7 @@ impl DynamicLibrary {
|
|||||||
/// Lazily open a dynamic library. When passed None it gives a
|
/// Lazily open a dynamic library. When passed None it gives a
|
||||||
/// handle to the calling process
|
/// handle to the calling process
|
||||||
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
|
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
|
||||||
let maybe_library = dl::open(filename.map(|path| path.as_vec()));
|
let maybe_library = dl::open(filename.map(|path| path.as_os_str()));
|
||||||
|
|
||||||
// The dynamic library must not be constructed if there is
|
// The dynamic library must not be constructed if there is
|
||||||
// an error opening the library so the destructor does not
|
// an error opening the library so the destructor does not
|
||||||
@@ -68,19 +67,17 @@ impl DynamicLibrary {
|
|||||||
/// Prepends a path to this process's search path for dynamic libraries
|
/// Prepends a path to this process's search path for dynamic libraries
|
||||||
pub fn prepend_search_path(path: &Path) {
|
pub fn prepend_search_path(path: &Path) {
|
||||||
let mut search_path = DynamicLibrary::search_path();
|
let mut search_path = DynamicLibrary::search_path();
|
||||||
search_path.insert(0, path.clone());
|
search_path.insert(0, path.to_path_buf());
|
||||||
let newval = DynamicLibrary::create_path(&search_path);
|
env::set_var(DynamicLibrary::envvar(), &DynamicLibrary::create_path(&search_path));
|
||||||
env::set_var(DynamicLibrary::envvar(),
|
|
||||||
str::from_utf8(&newval).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From a slice of paths, create a new vector which is suitable to be an
|
/// From a slice of paths, create a new vector which is suitable to be an
|
||||||
/// environment variable for this platforms dylib search path.
|
/// environment variable for this platforms dylib search path.
|
||||||
pub fn create_path(path: &[Path]) -> Vec<u8> {
|
pub fn create_path(path: &[PathBuf]) -> OsString {
|
||||||
let mut newvar = Vec::new();
|
let mut newvar = OsString::new();
|
||||||
for (i, path) in path.iter().enumerate() {
|
for (i, path) in path.iter().enumerate() {
|
||||||
if i > 0 { newvar.push(DynamicLibrary::separator()); }
|
if i > 0 { newvar.push(DynamicLibrary::separator()); }
|
||||||
newvar.push_all(path.as_vec());
|
newvar.push(path);
|
||||||
}
|
}
|
||||||
return newvar;
|
return newvar;
|
||||||
}
|
}
|
||||||
@@ -97,15 +94,15 @@ impl DynamicLibrary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn separator() -> u8 {
|
fn separator() -> &'static str {
|
||||||
if cfg!(windows) {b';'} else {b':'}
|
if cfg!(windows) { ";" } else { ":" }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current search path for dynamic libraries being used by this
|
/// Returns the current search path for dynamic libraries being used by this
|
||||||
/// process
|
/// process
|
||||||
pub fn search_path() -> Vec<Path> {
|
pub fn search_path() -> Vec<PathBuf> {
|
||||||
match env::var_os(DynamicLibrary::envvar()) {
|
match env::var_os(DynamicLibrary::envvar()) {
|
||||||
Some(var) => os::split_paths(var.to_str().unwrap()),
|
Some(var) => env::split_paths(&var).collect(),
|
||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,8 +131,8 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use prelude::v1::*;
|
use prelude::v1::*;
|
||||||
use libc;
|
use libc;
|
||||||
use old_path::Path;
|
|
||||||
use mem;
|
use mem;
|
||||||
|
use path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(any(windows, target_os = "android"), ignore)] // FIXME #8818, #10379
|
#[cfg_attr(any(windows, target_os = "android"), ignore)] // FIXME #8818, #10379
|
||||||
@@ -192,12 +189,13 @@ mod test {
|
|||||||
mod dl {
|
mod dl {
|
||||||
use prelude::v1::*;
|
use prelude::v1::*;
|
||||||
|
|
||||||
use ffi::{CString, CStr};
|
use ffi::{CStr, OsStr};
|
||||||
use str;
|
use str;
|
||||||
use libc;
|
use libc;
|
||||||
|
use os::unix::prelude::*;
|
||||||
use ptr;
|
use ptr;
|
||||||
|
|
||||||
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
|
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> {
|
||||||
check_for_errors_in(|| {
|
check_for_errors_in(|| {
|
||||||
unsafe {
|
unsafe {
|
||||||
match filename {
|
match filename {
|
||||||
@@ -210,8 +208,8 @@ mod dl {
|
|||||||
|
|
||||||
const LAZY: libc::c_int = 1;
|
const LAZY: libc::c_int = 1;
|
||||||
|
|
||||||
unsafe fn open_external(filename: &[u8]) -> *mut u8 {
|
unsafe fn open_external(filename: &OsStr) -> *mut u8 {
|
||||||
let s = CString::new(filename).unwrap();
|
let s = filename.to_cstring().unwrap();
|
||||||
dlopen(s.as_ptr(), LAZY) as *mut u8
|
dlopen(s.as_ptr(), LAZY) as *mut u8
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,21 +262,22 @@ mod dl {
|
|||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod dl {
|
mod dl {
|
||||||
|
use ffi::OsStr;
|
||||||
use iter::IteratorExt;
|
use iter::IteratorExt;
|
||||||
use libc;
|
use libc;
|
||||||
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
|
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
|
||||||
use ops::FnOnce;
|
use ops::FnOnce;
|
||||||
use os;
|
use os;
|
||||||
|
use os::windows::prelude::*;
|
||||||
use option::Option::{self, Some, None};
|
use option::Option::{self, Some, None};
|
||||||
use ptr;
|
use ptr;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use result::Result::{Ok, Err};
|
use result::Result::{Ok, Err};
|
||||||
use str;
|
|
||||||
use string::String;
|
use string::String;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
use sys::c::compat::kernel32::SetThreadErrorMode;
|
use sys::c::compat::kernel32::SetThreadErrorMode;
|
||||||
|
|
||||||
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
|
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> {
|
||||||
// disable "dll load failed" error dialog.
|
// disable "dll load failed" error dialog.
|
||||||
let mut use_thread_mode = true;
|
let mut use_thread_mode = true;
|
||||||
let prev_error_mode = unsafe {
|
let prev_error_mode = unsafe {
|
||||||
@@ -308,9 +307,8 @@ mod dl {
|
|||||||
|
|
||||||
let result = match filename {
|
let result = match filename {
|
||||||
Some(filename) => {
|
Some(filename) => {
|
||||||
let filename_str = str::from_utf8(filename).unwrap();
|
let filename_str: Vec<_> =
|
||||||
let mut filename_str: Vec<u16> = filename_str.utf16_units().collect();
|
filename.encode_wide().chain(Some(0).into_iter()).collect();
|
||||||
filename_str.push(0);
|
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
LoadLibraryW(filename_str.as_ptr() as *const libc::c_void)
|
LoadLibraryW(filename_str.as_ptr() as *const libc::c_void)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
//! this takes the route of using StackWalk64 in order to walk the stack.
|
//! this takes the route of using StackWalk64 in order to walk the stack.
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(deprecated)] // for old path for dynamic lib
|
|
||||||
|
|
||||||
use prelude::v1::*;
|
use prelude::v1::*;
|
||||||
use io::prelude::*;
|
use io::prelude::*;
|
||||||
@@ -34,7 +33,7 @@ use intrinsics;
|
|||||||
use io;
|
use io;
|
||||||
use libc;
|
use libc;
|
||||||
use mem;
|
use mem;
|
||||||
use old_path::Path;
|
use path::Path;
|
||||||
use ptr;
|
use ptr;
|
||||||
use str;
|
use str;
|
||||||
use sync::{StaticMutex, MUTEX_INIT};
|
use sync::{StaticMutex, MUTEX_INIT};
|
||||||
|
|||||||
Reference in New Issue
Block a user