Skip to content

Commit 6acf385

Browse files
committed
Updated std::dynamic_lib to use std::path.
1 parent b0aad7d commit 6acf385

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

src/librustc/plugin/load.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ use std::borrow::ToOwned;
1818
use std::dynamic_lib::DynamicLibrary;
1919
use std::env;
2020
use std::mem;
21-
22-
#[allow(deprecated)]
23-
use std::old_path;
24-
2521
use std::path::PathBuf;
2622
use syntax::ast;
2723
use syntax::codemap::{Span, COMMAND_LINE_SP};
@@ -110,7 +106,6 @@ impl<'a> PluginLoader<'a> {
110106
symbol: String) -> PluginRegistrarFun {
111107
// Make sure the path contains a / or the linker will search for it.
112108
let path = env::current_dir().unwrap().join(&path);
113-
let path = old_path::Path::new(path.to_str().unwrap());
114109

115110
let lib = match DynamicLibrary::open(Some(&path)) {
116111
Ok(lib) => lib,

src/libstd/dynamic_lib.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
1515
#![unstable(feature = "std_misc")]
1616
#![allow(missing_docs)]
17-
#![allow(deprecated)] // will be addressed by #23197
1817

1918
use prelude::v1::*;
2019

2120
use env;
22-
use ffi::CString;
21+
use ffi::{AsOsStr, CString, OsString};
2322
use mem;
24-
use old_path::{Path, GenericPath};
25-
use os;
26-
use str;
23+
use path::{Path, PathBuf};
24+
#[cfg(not(target_os = "android"))] use os;
25+
#[cfg(not(target_os = "android"))] use str;
2726

2827
pub struct DynamicLibrary {
2928
handle: *mut u8
@@ -54,7 +53,7 @@ impl DynamicLibrary {
5453
/// Lazily open a dynamic library. When passed None it gives a
5554
/// handle to the calling process
5655
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
57-
let maybe_library = dl::open(filename.map(|path| path.as_vec()));
56+
let maybe_library = dl::open(filename.map(|path| path.as_os_str()));
5857

5958
// The dynamic library must not be constructed if there is
6059
// an error opening the library so the destructor does not
@@ -68,19 +67,17 @@ impl DynamicLibrary {
6867
/// Prepends a path to this process's search path for dynamic libraries
6968
pub fn prepend_search_path(path: &Path) {
7069
let mut search_path = DynamicLibrary::search_path();
71-
search_path.insert(0, path.clone());
72-
let newval = DynamicLibrary::create_path(&search_path);
73-
env::set_var(DynamicLibrary::envvar(),
74-
str::from_utf8(&newval).unwrap());
70+
search_path.insert(0, path.to_path_buf());
71+
env::set_var(DynamicLibrary::envvar(), &DynamicLibrary::create_path(&search_path));
7572
}
7673

7774
/// From a slice of paths, create a new vector which is suitable to be an
7875
/// environment variable for this platforms dylib search path.
79-
pub fn create_path(path: &[Path]) -> Vec<u8> {
80-
let mut newvar = Vec::new();
76+
pub fn create_path(path: &[PathBuf]) -> OsString {
77+
let mut newvar = OsString::new();
8178
for (i, path) in path.iter().enumerate() {
8279
if i > 0 { newvar.push(DynamicLibrary::separator()); }
83-
newvar.push_all(path.as_vec());
80+
newvar.push(path);
8481
}
8582
return newvar;
8683
}
@@ -97,15 +94,15 @@ impl DynamicLibrary {
9794
}
9895
}
9996

100-
fn separator() -> u8 {
101-
if cfg!(windows) {b';'} else {b':'}
97+
fn separator() -> &'static str {
98+
if cfg!(windows) { ";" } else { ":" }
10299
}
103100

104101
/// Returns the current search path for dynamic libraries being used by this
105102
/// process
106-
pub fn search_path() -> Vec<Path> {
103+
pub fn search_path() -> Vec<PathBuf> {
107104
match env::var_os(DynamicLibrary::envvar()) {
108-
Some(var) => os::split_paths(var.to_str().unwrap()),
105+
Some(var) => env::split_paths(&var).collect(),
109106
None => Vec::new(),
110107
}
111108
}
@@ -134,8 +131,8 @@ mod test {
134131
use super::*;
135132
use prelude::v1::*;
136133
use libc;
137-
use old_path::Path;
138134
use mem;
135+
use path::Path;
139136

140137
#[test]
141138
#[cfg_attr(any(windows, target_os = "android"), ignore)] // FIXME #8818, #10379
@@ -192,12 +189,13 @@ mod test {
192189
mod dl {
193190
use prelude::v1::*;
194191

195-
use ffi::{CString, CStr};
192+
use ffi::{CStr, OsStr};
196193
use str;
197194
use libc;
195+
use os::unix::prelude::*;
198196
use ptr;
199197

200-
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
198+
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> {
201199
check_for_errors_in(|| {
202200
unsafe {
203201
match filename {
@@ -210,8 +208,8 @@ mod dl {
210208

211209
const LAZY: libc::c_int = 1;
212210

213-
unsafe fn open_external(filename: &[u8]) -> *mut u8 {
214-
let s = CString::new(filename).unwrap();
211+
unsafe fn open_external(filename: &OsStr) -> *mut u8 {
212+
let s = filename.to_cstring().unwrap();
215213
dlopen(s.as_ptr(), LAZY) as *mut u8
216214
}
217215

@@ -264,21 +262,22 @@ mod dl {
264262

265263
#[cfg(target_os = "windows")]
266264
mod dl {
265+
use ffi::OsStr;
267266
use iter::IteratorExt;
268267
use libc;
269268
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
270269
use ops::FnOnce;
271270
use os;
271+
use os::windows::prelude::*;
272272
use option::Option::{self, Some, None};
273273
use ptr;
274274
use result::Result;
275275
use result::Result::{Ok, Err};
276-
use str;
277276
use string::String;
278277
use vec::Vec;
279278
use sys::c::compat::kernel32::SetThreadErrorMode;
280279

281-
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
280+
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> {
282281
// disable "dll load failed" error dialog.
283282
let mut use_thread_mode = true;
284283
let prev_error_mode = unsafe {
@@ -308,9 +307,8 @@ mod dl {
308307

309308
let result = match filename {
310309
Some(filename) => {
311-
let filename_str = str::from_utf8(filename).unwrap();
312-
let mut filename_str: Vec<u16> = filename_str.utf16_units().collect();
313-
filename_str.push(0);
310+
let filename_str: Vec<_> =
311+
filename.encode_wide().chain(Some(0).into_iter()).collect();
314312
let result = unsafe {
315313
LoadLibraryW(filename_str.as_ptr() as *const libc::c_void)
316314
};

src/libstd/sys/windows/backtrace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
//! this takes the route of using StackWalk64 in order to walk the stack.
2424
2525
#![allow(dead_code)]
26-
#![allow(deprecated)] // for old path for dynamic lib
2726

2827
use prelude::v1::*;
2928
use io::prelude::*;
@@ -34,7 +33,7 @@ use intrinsics;
3433
use io;
3534
use libc;
3635
use mem;
37-
use old_path::Path;
36+
use path::Path;
3837
use ptr;
3938
use str;
4039
use sync::{StaticMutex, MUTEX_INIT};

0 commit comments

Comments
 (0)