]> git.lizzy.rs Git - rust.git/commitdiff
Rename conversion util; remove duplicate util in librustc_codegen_llvm.
authorCorey Farwell <coreyf@rwell.org>
Thu, 29 Nov 2018 13:09:28 +0000 (08:09 -0500)
committerCorey Farwell <coreyf@rwell.org>
Thu, 29 Nov 2018 13:09:28 +0000 (08:09 -0500)
src/librustc_codegen_llvm/back/write.rs
src/librustc_codegen_llvm/debuginfo/metadata.rs
src/librustc_codegen_llvm/llvm/archive_ro.rs
src/librustc_codegen_llvm/metadata.rs
src/librustc_fs_util/lib.rs

index 7945d381760a1b082a711014135b2948a5585ff4..4eb920324bd003070634fae5c4d5a2ce6fe2940e 100644 (file)
@@ -23,7 +23,7 @@
 use ModuleLlvm;
 use rustc_codegen_ssa::{ModuleCodegen, CompiledModule};
 use rustc::util::common::time_ext;
-use rustc_fs_util::{path2cstr, link_or_copy};
+use rustc_fs_util::{path_to_c_string, link_or_copy};
 use rustc_data_structures::small_c_str::SmallCStr;
 use errors::{self, Handler, FatalError};
 use type_::Type;
@@ -80,7 +80,7 @@ pub fn write_output_file(
         output: &Path,
         file_type: llvm::FileType) -> Result<(), FatalError> {
     unsafe {
-        let output_c = path2cstr(output);
+        let output_c = path_to_c_string(output);
         let result = llvm::LLVMRustWriteOutputFile(target, pm, m, output_c.as_ptr(), file_type);
         if result.into_result().is_err() {
             let msg = format!("could not write output to {}", output.display());
@@ -211,7 +211,7 @@ pub(crate) fn save_temp_bitcode(
         let ext = format!("{}.bc", name);
         let cgu = Some(&module.name[..]);
         let path = cgcx.output_filenames.temp_path_ext(&ext, cgu);
-        let cstr = path2cstr(&path);
+        let cstr = path_to_c_string(&path);
         let llmod = module.module_llvm.llmod();
         llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
     }
@@ -324,7 +324,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
 
     if config.emit_no_opt_bc {
         let out = cgcx.output_filenames.temp_path_ext("no-opt.bc", module_name);
-        let out = path2cstr(&out);
+        let out = path_to_c_string(&out);
         llvm::LLVMWriteBitcodeToFile(llmod, out.as_ptr());
     }
 
@@ -530,7 +530,7 @@ unsafe fn with_codegen<'ll, F, R>(tm: &'ll llvm::TargetMachine,
             || -> Result<(), FatalError> {
             if config.emit_ir {
                 let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
-                let out = path2cstr(&out);
+                let out = path_to_c_string(&out);
 
                 extern "C" fn demangle_callback(input_ptr: *const c_char,
                                                 input_len: size_t,
index 81f2769800d2f190a96a4d7d8ceb4594fcccbf91..47e92fbe87d31bb8b3b9739f937c280aff262ae1 100644 (file)
@@ -39,7 +39,7 @@
                         PrimitiveExt, Size, TyLayout};
 use rustc::session::config;
 use rustc::util::nodemap::FxHashMap;
-use rustc_fs_util::path2cstr;
+use rustc_fs_util::path_to_c_string;
 use rustc_data_structures::small_c_str::SmallCStr;
 
 use libc::{c_uint, c_longlong};
@@ -892,7 +892,7 @@ pub fn compile_unit_metadata(tcx: TyCtxt,
     };
 
     fn path_to_mdstring(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value {
-        let path_str = path2cstr(path);
+        let path_str = path_to_c_string(path);
         unsafe {
             llvm::LLVMMDStringInContext(llcx,
                                         path_str.as_ptr(),
index 2a77f256e3a0cd4f93bf489dc94dce692633dff1..d5c73fecf814a80cf7c0b947d364dece00d57732 100644 (file)
 
 //! A wrapper around LLVM's archive (.a) code
 
-use std::ffi::CString;
 use std::path::Path;
 use std::slice;
 use std::str;
+use rustc_fs_util::path_to_c_string;
 
 pub struct ArchiveRO {
     pub raw: &'static mut super::Archive,
@@ -38,24 +38,12 @@ impl ArchiveRO {
     /// raised.
     pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
         return unsafe {
-            let s = path2cstr(dst);
+            let s = path_to_c_string(dst);
             let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
                 super::last_error().unwrap_or_else(|| "failed to open archive".to_owned())
             })?;
             Ok(ArchiveRO { raw: ar })
         };
-
-        #[cfg(unix)]
-        fn path2cstr(p: &Path) -> CString {
-            use std::os::unix::prelude::*;
-            use std::ffi::OsStr;
-            let p: &OsStr = p.as_ref();
-            CString::new(p.as_bytes()).unwrap()
-        }
-        #[cfg(windows)]
-        fn path2cstr(p: &Path) -> CString {
-            CString::new(p.to_str().unwrap()).unwrap()
-        }
     }
 
     pub fn iter(&self) -> Iter {
index 7752465d885bbff47574b533b7bc8cc4f669af29..5605f64c2e72c2d62304c2d3f61a256da0543520 100644 (file)
@@ -18,7 +18,7 @@
 use std::path::Path;
 use std::ptr;
 use std::slice;
-use rustc_fs_util::path2cstr;
+use rustc_fs_util::path_to_c_string;
 
 pub use rustc_data_structures::sync::MetadataRef;
 
@@ -57,7 +57,7 @@ fn get_dylib_metadata(&self,
                           filename: &Path)
                           -> Result<MetadataRef, String> {
         unsafe {
-            let buf = path2cstr(filename);
+            let buf = path_to_c_string(filename);
             let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr())
                 .ok_or_else(|| format!("error reading library: '{}'", filename.display()))?;
             let of = ObjectFile::new(mb)
index ffe420b109d3ecf6cea04f377e53f357a4c6b58f..1b0ff4f861c7be6c65cde0c1a143160db0328e9d 100644 (file)
@@ -116,13 +116,13 @@ pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
 }
 
 #[cfg(unix)]
-pub fn path2cstr(p: &Path) -> CString {
-    use std::os::unix::prelude::*;
+pub fn path_to_c_string(p: &Path) -> CString {
+    use std::os::unix::ffi::OsStrExt;
     use std::ffi::OsStr;
     let p: &OsStr = p.as_ref();
     CString::new(p.as_bytes()).unwrap()
 }
 #[cfg(windows)]
-pub fn path2cstr(p: &Path) -> CString {
+pub fn path_to_c_string(p: &Path) -> CString {
     CString::new(p.to_str().unwrap()).unwrap()
 }