Skip to content

Commit 2a91bba

Browse files
committedNov 29, 2018

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed
 

‎src/librustc_codegen_llvm/back/write.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use llvm_util;
2323
use ModuleLlvm;
2424
use rustc_codegen_ssa::{ModuleCodegen, CompiledModule};
2525
use rustc::util::common::time_ext;
26-
use rustc_fs_util::{path2cstr, link_or_copy};
26+
use rustc_fs_util::{path_to_c_string, link_or_copy};
2727
use rustc_data_structures::small_c_str::SmallCStr;
2828
use errors::{self, Handler, FatalError};
2929
use type_::Type;
@@ -80,7 +80,7 @@ pub fn write_output_file(
8080
output: &Path,
8181
file_type: llvm::FileType) -> Result<(), FatalError> {
8282
unsafe {
83-
let output_c = path2cstr(output);
83+
let output_c = path_to_c_string(output);
8484
let result = llvm::LLVMRustWriteOutputFile(target, pm, m, output_c.as_ptr(), file_type);
8585
if result.into_result().is_err() {
8686
let msg = format!("could not write output to {}", output.display());
@@ -211,7 +211,7 @@ pub(crate) fn save_temp_bitcode(
211211
let ext = format!("{}.bc", name);
212212
let cgu = Some(&module.name[..]);
213213
let path = cgcx.output_filenames.temp_path_ext(&ext, cgu);
214-
let cstr = path2cstr(&path);
214+
let cstr = path_to_c_string(&path);
215215
let llmod = module.module_llvm.llmod();
216216
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
217217
}
@@ -324,7 +324,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
324324

325325
if config.emit_no_opt_bc {
326326
let out = cgcx.output_filenames.temp_path_ext("no-opt.bc", module_name);
327-
let out = path2cstr(&out);
327+
let out = path_to_c_string(&out);
328328
llvm::LLVMWriteBitcodeToFile(llmod, out.as_ptr());
329329
}
330330

@@ -530,7 +530,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
530530
|| -> Result<(), FatalError> {
531531
if config.emit_ir {
532532
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
533-
let out = path2cstr(&out);
533+
let out = path_to_c_string(&out);
534534

535535
extern "C" fn demangle_callback(input_ptr: *const c_char,
536536
input_len: size_t,

‎src/librustc_codegen_llvm/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc::ty::layout::{self, Align, HasDataLayout, Integer, IntegerExt, LayoutO
3939
PrimitiveExt, Size, TyLayout};
4040
use rustc::session::config;
4141
use rustc::util::nodemap::FxHashMap;
42-
use rustc_fs_util::path2cstr;
42+
use rustc_fs_util::path_to_c_string;
4343
use rustc_data_structures::small_c_str::SmallCStr;
4444

4545
use libc::{c_uint, c_longlong};
@@ -892,7 +892,7 @@ pub fn compile_unit_metadata(tcx: TyCtxt,
892892
};
893893

894894
fn path_to_mdstring(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value {
895-
let path_str = path2cstr(path);
895+
let path_str = path_to_c_string(path);
896896
unsafe {
897897
llvm::LLVMMDStringInContext(llcx,
898898
path_str.as_ptr(),

‎src/librustc_codegen_llvm/llvm/archive_ro.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
//! A wrapper around LLVM's archive (.a) code
1212
13-
use std::ffi::CString;
1413
use std::path::Path;
1514
use std::slice;
1615
use std::str;
16+
use rustc_fs_util::path_to_c_string;
1717

1818
pub struct ArchiveRO {
1919
pub raw: &'static mut super::Archive,
@@ -38,24 +38,12 @@ impl ArchiveRO {
3838
/// raised.
3939
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
4040
return unsafe {
41-
let s = path2cstr(dst);
41+
let s = path_to_c_string(dst);
4242
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
4343
super::last_error().unwrap_or_else(|| "failed to open archive".to_owned())
4444
})?;
4545
Ok(ArchiveRO { raw: ar })
4646
};
47-
48-
#[cfg(unix)]
49-
fn path2cstr(p: &Path) -> CString {
50-
use std::os::unix::prelude::*;
51-
use std::ffi::OsStr;
52-
let p: &OsStr = p.as_ref();
53-
CString::new(p.as_bytes()).unwrap()
54-
}
55-
#[cfg(windows)]
56-
fn path2cstr(p: &Path) -> CString {
57-
CString::new(p.to_str().unwrap()).unwrap()
58-
}
5947
}
6048

6149
pub fn iter(&self) -> Iter {

‎src/librustc_codegen_llvm/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::owning_ref::OwningRef;
1818
use std::path::Path;
1919
use std::ptr;
2020
use std::slice;
21-
use rustc_fs_util::path2cstr;
21+
use rustc_fs_util::path_to_c_string;
2222

2323
pub use rustc_data_structures::sync::MetadataRef;
2424

@@ -57,7 +57,7 @@ impl MetadataLoader for LlvmMetadataLoader {
5757
filename: &Path)
5858
-> Result<MetadataRef, String> {
5959
unsafe {
60-
let buf = path2cstr(filename);
60+
let buf = path_to_c_string(filename);
6161
let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr())
6262
.ok_or_else(|| format!("error reading library: '{}'", filename.display()))?;
6363
let of = ObjectFile::new(mb)

‎src/librustc_fs_util/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
116116
}
117117

118118
#[cfg(unix)]
119-
pub fn path2cstr(p: &Path) -> CString {
120-
use std::os::unix::prelude::*;
119+
pub fn path_to_c_string(p: &Path) -> CString {
120+
use std::os::unix::ffi::OsStrExt;
121121
use std::ffi::OsStr;
122122
let p: &OsStr = p.as_ref();
123123
CString::new(p.as_bytes()).unwrap()
124124
}
125125
#[cfg(windows)]
126-
pub fn path2cstr(p: &Path) -> CString {
126+
pub fn path_to_c_string(p: &Path) -> CString {
127127
CString::new(p.to_str().unwrap()).unwrap()
128128
}

0 commit comments

Comments
 (0)
Please sign in to comment.