]> git.lizzy.rs Git - rust.git/commitdiff
rustc_codegen_llvm: use safe references for Linker.
authorIrina Popa <irinagpopa@gmail.com>
Tue, 17 Jul 2018 11:26:22 +0000 (14:26 +0300)
committerIrina Popa <irinagpopa@gmail.com>
Mon, 30 Jul 2018 17:10:41 +0000 (20:10 +0300)
src/librustc_codegen_llvm/back/lto.rs
src/librustc_codegen_llvm/llvm/ffi.rs

index 0a8b143ae9235d3e43e3611b8cab3d9c8226f2ef..d5d21eb91ecba497c9538ab0c6c20e63e6ee9788 100644 (file)
@@ -294,10 +294,10 @@ fn fat_lto(cgcx: &CodegenContext,
     }])
 }
 
-struct Linker(llvm::LinkerRef);
+struct Linker<'a>(&'a mut llvm::Linker<'a>);
 
-impl Linker {
-    fn new(llmod: &llvm::Module) -> Linker {
+impl Linker<'a> {
+    fn new(llmod: &'a llvm::Module) -> Self {
         unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
     }
 
@@ -314,9 +314,9 @@ fn add(&mut self, bytecode: &[u8]) -> Result<(), ()> {
     }
 }
 
-impl Drop for Linker {
+impl Drop for Linker<'a> {
     fn drop(&mut self) {
-        unsafe { llvm::LLVMRustLinkerFree(self.0); }
+        unsafe { llvm::LLVMRustLinkerFree(&mut *(self.0 as *mut _)); }
     }
 }
 
index 4b1e8e0626131cc31229019ab19c8658ae37a4ba..ddd7809abc7314069e0910e9bf43ec0d3e159bc4 100644 (file)
@@ -414,8 +414,7 @@ struct InvariantOpaque<'a> {
 extern { pub type RustArchiveMember; }
 pub type RustArchiveMemberRef = *mut RustArchiveMember;
 pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
-extern { pub type Linker; }
-pub type LinkerRef = *mut Linker;
+pub struct Linker<'a>(InvariantOpaque<'a>);
 
 pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
 pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
@@ -1580,9 +1579,9 @@ pub fn LLVMRustThinLTOGetDICompileUnit(M: &Module,
                                            CU2: &mut *mut c_void);
     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
 
-    pub fn LLVMRustLinkerNew(M: &Module) -> LinkerRef;
-    pub fn LLVMRustLinkerAdd(linker: LinkerRef,
+    pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
+    pub fn LLVMRustLinkerAdd(linker: &Linker,
                              bytecode: *const c_char,
                              bytecode_len: usize) -> bool;
-    pub fn LLVMRustLinkerFree(linker: LinkerRef);
+    pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
 }