Skip to content

Commit 2c1d7fb

Browse files
committed
rustc_codegen_llvm: use safe references for SectionIterator.
1 parent e22eeba commit 2c1d7fb

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ extern { pub type MemoryBuffer; }
400400
pub struct PassManager<'a>(InvariantOpaque<'a>);
401401
extern { pub type PassManagerBuilder; }
402402
extern { pub type ObjectFile; }
403-
extern { pub type SectionIterator; }
404-
pub type SectionIteratorRef = *mut SectionIterator;
403+
pub struct SectionIterator<'a>(InvariantOpaque<'a>);
405404
extern { pub type Pass; }
406405
extern { pub type TargetMachine; }
407406
extern { pub type Archive; }
@@ -1146,18 +1145,18 @@ extern "C" {
11461145
pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
11471146

11481147
/// Enumerates the sections in an object file.
1149-
pub fn LLVMGetSections(ObjFile: &ObjectFile) -> SectionIteratorRef;
1148+
pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
11501149
/// Destroys a section iterator.
1151-
pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1150+
pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
11521151
/// Returns true if the section iterator is at the end of the section
11531152
/// list:
1154-
pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &ObjectFile, SI: SectionIteratorRef) -> Bool;
1153+
pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
11551154
/// Moves the section iterator to point to the next section.
1156-
pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1155+
pub fn LLVMMoveToNextSection(SI: &SectionIterator);
11571156
/// Returns the current section size.
1158-
pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1157+
pub fn LLVMGetSectionSize(SI: &SectionIterator) -> c_ulonglong;
11591158
/// Returns the current section contents as a string buffer.
1160-
pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1159+
pub fn LLVMGetSectionContents(SI: &SectionIterator) -> *const c_char;
11611160

11621161
/// Reads the given file and returns it as a memory buffer. Use
11631162
/// LLVMDisposeMemoryBuffer() to get rid of it.
@@ -1481,7 +1480,7 @@ extern "C" {
14811480
pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
14821481
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
14831482

1484-
pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: &mut *const c_char) -> size_t;
1483+
pub fn LLVMRustGetSectionName(SI: &SectionIterator, data: &mut *const c_char) -> size_t;
14851484

14861485
pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
14871486

src/librustc_codegen_llvm/llvm/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,19 @@ impl Drop for ObjectFile {
204204

205205
// Memory-managed interface to section iterators.
206206

207-
pub struct SectionIter {
208-
pub llsi: SectionIteratorRef,
207+
pub struct SectionIter<'a> {
208+
pub llsi: &'a mut SectionIterator<'a>,
209209
}
210210

211-
impl Drop for SectionIter {
211+
impl Drop for SectionIter<'a> {
212212
fn drop(&mut self) {
213213
unsafe {
214-
LLVMDisposeSectionIterator(self.llsi);
214+
LLVMDisposeSectionIterator(&mut *(self.llsi as *mut _));
215215
}
216216
}
217217
}
218218

219-
pub fn mk_section_iter(llof: &ffi::ObjectFile) -> SectionIter {
219+
pub fn mk_section_iter(llof: &'a ffi::ObjectFile) -> SectionIter<'a> {
220220
unsafe { SectionIter { llsi: LLVMGetSections(llof) } }
221221
}
222222

0 commit comments

Comments
 (0)