Skip to content

Commit

Permalink
rustc_codegen_llvm: use safe references for ArchiveIterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinagpopa committed Jul 30, 2018
1 parent 894467e commit e551ed9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/librustc_codegen_llvm/llvm/archive_ro.rs
Expand Up @@ -23,8 +23,7 @@ pub struct ArchiveRO {
unsafe impl Send for ArchiveRO {}

pub struct Iter<'a> {
ptr: super::ArchiveIteratorRef,
_data: marker::PhantomData<&'a ArchiveRO>,
ptr: &'a mut super::ArchiveIterator<'a>,
}

pub struct Child<'a> {
Expand Down Expand Up @@ -68,7 +67,6 @@ impl ArchiveRO {
unsafe {
Iter {
ptr: super::LLVMRustArchiveIteratorNew(self.raw),
_data: marker::PhantomData,
}
}
}
Expand Down Expand Up @@ -101,7 +99,7 @@ impl<'a> Iterator for Iter<'a> {
impl<'a> Drop for Iter<'a> {
fn drop(&mut self) {
unsafe {
super::LLVMRustArchiveIteratorFree(self.ptr);
super::LLVMRustArchiveIteratorFree(&mut *(self.ptr as *mut _));
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Expand Up @@ -404,8 +404,7 @@ pub struct SectionIterator<'a>(InvariantOpaque<'a>);
extern { pub type Pass; }
extern { pub type TargetMachine; }
extern { pub type Archive; }
extern { pub type ArchiveIterator; }
pub type ArchiveIteratorRef = *mut ArchiveIterator;
pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
extern { pub type ArchiveChild; }
pub type ArchiveChildRef = *mut ArchiveChild;
extern { pub type Twine; }
Expand Down Expand Up @@ -1471,12 +1470,12 @@ extern "C" {
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);

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 LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
pub fn LLVMRustArchiveIteratorNext(AIR: &ArchiveIterator) -> 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 LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);

pub fn LLVMRustGetSectionName(SI: &SectionIterator, data: &mut *const c_char) -> size_t;
Expand Down

0 comments on commit e551ed9

Please sign in to comment.