Skip to content

Commit e551ed9

Browse files
committed
rustc_codegen_llvm: use safe references for ArchiveIterator.
1 parent 894467e commit e551ed9

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/librustc_codegen_llvm/llvm/archive_ro.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ pub struct ArchiveRO {
2323
unsafe impl Send for ArchiveRO {}
2424

2525
pub struct Iter<'a> {
26-
ptr: super::ArchiveIteratorRef,
27-
_data: marker::PhantomData<&'a ArchiveRO>,
26+
ptr: &'a mut super::ArchiveIterator<'a>,
2827
}
2928

3029
pub struct Child<'a> {
@@ -68,7 +67,6 @@ impl ArchiveRO {
6867
unsafe {
6968
Iter {
7069
ptr: super::LLVMRustArchiveIteratorNew(self.raw),
71-
_data: marker::PhantomData,
7270
}
7371
}
7472
}
@@ -101,7 +99,7 @@ impl<'a> Iterator for Iter<'a> {
10199
impl<'a> Drop for Iter<'a> {
102100
fn drop(&mut self) {
103101
unsafe {
104-
super::LLVMRustArchiveIteratorFree(self.ptr);
102+
super::LLVMRustArchiveIteratorFree(&mut *(self.ptr as *mut _));
105103
}
106104
}
107105
}

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ pub struct SectionIterator<'a>(InvariantOpaque<'a>);
404404
extern { pub type Pass; }
405405
extern { pub type TargetMachine; }
406406
extern { pub type Archive; }
407-
extern { pub type ArchiveIterator; }
408-
pub type ArchiveIteratorRef = *mut ArchiveIterator;
407+
pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
409408
extern { pub type ArchiveChild; }
410409
pub type ArchiveChildRef = *mut ArchiveChild;
411410
extern { pub type Twine; }
@@ -1471,12 +1470,12 @@ extern "C" {
14711470
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
14721471

14731472
pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
1474-
pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> ArchiveIteratorRef;
1475-
pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
1473+
pub fn LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
1474+
pub fn LLVMRustArchiveIteratorNext(AIR: &ArchiveIterator) -> ArchiveChildRef;
14761475
pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef, size: &mut size_t) -> *const c_char;
14771476
pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef, size: &mut size_t) -> *const c_char;
14781477
pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
1479-
pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
1478+
pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
14801479
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
14811480

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

0 commit comments

Comments
 (0)