Skip to content

rustc_codegen_llvm: use safe references for LLVM FFI types. #52461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
077be49
rustc_llvm: move to rustc_codegen_llvm::llvm.
irinagpopa May 29, 2018
af04e94
rustc_codegen_llvm: move from empty enums to extern types.
irinagpopa Jun 27, 2018
249d5ac
rustc_codegen_llvm: use safe references for Context and Module.
irinagpopa Jun 27, 2018
d04e66d
rustc_codegen_llvm: use safe references for Type.
irinagpopa Jul 2, 2018
2dbde55
rustc_codegen_llvm: use safe references for Builder.
irinagpopa Jul 3, 2018
6d0d82c
rustc_codegen_llvm: use safe references for DIBuilder.
irinagpopa Jul 3, 2018
eed48f5
rustc_codegen_llvm: use safe references for Metadata and DI*.
irinagpopa Jul 4, 2018
50d7642
rustc_codegen_llvm: remove unused ExecutionEngineRef type.
irinagpopa Jul 4, 2018
1da2670
rustc_codegen_llvm: remove #![allow(dead_code)] from llvm.
irinagpopa Jul 4, 2018
8d17684
rustc_codegen_llvm: remove _opaque suffix.
irinagpopa Jul 5, 2018
f375185
rustc_codegen_llvm: use safe references for Value.
irinagpopa Jul 10, 2018
3eb5035
rustc_codegen_llvm: use safe references for BasicBlock.
irinagpopa Jul 10, 2018
f224441
rustc_codegen_llvm: remove unused UseRef type.
irinagpopa Jul 10, 2018
ebec156
rustc_codegen_llvm: remove more unused functions.
irinagpopa Jul 10, 2018
2f73cef
rustc_codegen_llvm: use safe references for MemoryBuffer and ObjectFile.
irinagpopa Jul 10, 2018
e954660
rustc_codegen_llvm: use safe references for PassManagerBuilder.
irinagpopa Jul 12, 2018
55af020
rustc_codegen_llvm: use safe references for Pass.
irinagpopa Jul 12, 2018
0e3a705
rustc_codegen_llvm: use safe references for TargetMachine.
irinagpopa Jul 12, 2018
41d7d8e
rustc_codegen_llvm: use safe references for Archive.
irinagpopa Jul 13, 2018
44ae6f1
rustc_codegen_llvm: use safe references for Twine, DiagnosticInfo, SM…
irinagpopa Jul 13, 2018
c1eeb69
rustc_codegen_llvm: use safe references for RustString.
irinagpopa Jul 13, 2018
92af969
rustc_codegen_llvm: use safe mutable references for output parameters.
irinagpopa Jul 13, 2018
0ab3444
rustc_codegen_llvm: use safe references for OperandBundleDef.
irinagpopa Jul 16, 2018
e22eeba
rustc_codegen_llvm: use safe references for PassManager.
irinagpopa Jul 17, 2018
2c1d7fb
rustc_codegen_llvm: use safe references for SectionIterator.
irinagpopa Jul 17, 2018
894467e
rustc_codegen_llvm: use safe references for Linker.
irinagpopa Jul 17, 2018
e551ed9
rustc_codegen_llvm: use safe references for ArchiveIterator.
irinagpopa Jul 17, 2018
c7669df
rustc_codegen_llvm: use safe references for ArchiveChild.
irinagpopa Jul 17, 2018
b643e51
rustc_codegen_llvm: use safe references for RustArchiveMember.
irinagpopa Jul 17, 2018
ab4f93c
rustc_codegen_llvm: use safe references for ModuleBuffer.
irinagpopa Jul 17, 2018
2e3a6af
rustc_codegen_llvm: use safe references for ThinLTOBuffer.
irinagpopa Jul 17, 2018
ba00644
rustc_codegen_llvm: use safe references for ThinLTOData.
irinagpopa Jul 17, 2018
265f2fa
rustc_codegen_llvm: fix tidy errors.
irinagpopa Jul 17, 2018
54c98ab
rustc_codegen_llvm: fix ownership of Builder.
irinagpopa Jul 17, 2018
69ed6b9
rustc_codegen_llvm: fix ownership of DIBuilder.
irinagpopa Jul 17, 2018
baff67d
rustc_llvm: fix linking on mingw.
irinagpopa Jul 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rustc_codegen_llvm: use safe references for Archive.
  • Loading branch information
irinagpopa committed Jul 30, 2018
commit 41d7d8e35e54576d55dc6ed3649a6a6e7d6b749e
21 changes: 8 additions & 13 deletions src/librustc_codegen_llvm/llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@

//! A wrapper around LLVM's archive (.a) code

use super::ArchiveRef;

use std::ffi::CString;
use std::marker;
use std::path::Path;
use std::slice;
use std::str;

pub struct ArchiveRO {
ptr: ArchiveRef,
raw: &'static mut super::Archive,
}

unsafe impl Send for ArchiveRO {}
Expand All @@ -44,12 +42,9 @@ impl ArchiveRO {
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
return unsafe {
let s = path2cstr(dst);
let ar = super::LLVMRustOpenArchive(s.as_ptr());
if ar.is_null() {
Err(super::last_error().unwrap_or("failed to open archive".to_string()))
} else {
Ok(ArchiveRO { ptr: ar })
}
let ar = super::LLVMRustOpenArchive(s.as_ptr())
.ok_or_else(|| super::last_error().unwrap_or("failed to open archive".to_string()))?;
Ok(ArchiveRO { raw: ar })
};

#[cfg(unix)]
Expand All @@ -65,14 +60,14 @@ impl ArchiveRO {
}
}

pub fn raw(&self) -> ArchiveRef {
self.ptr
pub fn raw(&self) -> &super::Archive {
self.raw
}

pub fn iter(&self) -> Iter {
unsafe {
Iter {
ptr: super::LLVMRustArchiveIteratorNew(self.ptr),
ptr: super::LLVMRustArchiveIteratorNew(self.raw),
_data: marker::PhantomData,
}
}
Expand All @@ -82,7 +77,7 @@ impl ArchiveRO {
impl Drop for ArchiveRO {
fn drop(&mut self) {
unsafe {
super::LLVMRustDestroyArchive(self.ptr);
super::LLVMRustDestroyArchive(&mut *(self.raw as *mut _));
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ pub type SectionIteratorRef = *mut SectionIterator;
extern { pub type Pass; }
extern { pub type TargetMachine; }
extern { pub type Archive; }
pub type ArchiveRef = *mut Archive;
extern { pub type ArchiveIterator; }
pub type ArchiveIteratorRef = *mut ArchiveIterator;
extern { pub type ArchiveChild; }
Expand Down Expand Up @@ -1471,14 +1470,14 @@ extern "C" {
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);

pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> ArchiveIteratorRef;
pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char;
pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char;
pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);

pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: *mut *const c_char) -> size_t;

Expand Down