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

index 7883315a5dec50b51d996e7a0e798b00ce66784f..4b1e8e0626131cc31229019ab19c8658ae37a4ba 100644 (file)
@@ -400,8 +400,7 @@ struct InvariantOpaque<'a> {
 pub struct PassManager<'a>(InvariantOpaque<'a>);
 extern { pub type PassManagerBuilder; }
 extern { pub type ObjectFile; }
-extern { pub type SectionIterator; }
-pub type SectionIteratorRef = *mut SectionIterator;
+pub struct SectionIterator<'a>(InvariantOpaque<'a>);
 extern { pub type Pass; }
 extern { pub type TargetMachine; }
 extern { pub type Archive; }
@@ -1146,18 +1145,18 @@ pub fn LLVMCreateObjectFile(
     pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
 
     /// Enumerates the sections in an object file.
-    pub fn LLVMGetSections(ObjFile: &ObjectFile) -> SectionIteratorRef;
+    pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
     /// Destroys a section iterator.
-    pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
+    pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
     /// Returns true if the section iterator is at the end of the section
     /// list:
-    pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &ObjectFile, SI: SectionIteratorRef) -> Bool;
+    pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
     /// Moves the section iterator to point to the next section.
-    pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
+    pub fn LLVMMoveToNextSection(SI: &SectionIterator);
     /// Returns the current section size.
-    pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
+    pub fn LLVMGetSectionSize(SI: &SectionIterator) -> c_ulonglong;
     /// Returns the current section contents as a string buffer.
-    pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
+    pub fn LLVMGetSectionContents(SI: &SectionIterator) -> *const c_char;
 
     /// Reads the given file and returns it as a memory buffer. Use
     /// LLVMDisposeMemoryBuffer() to get rid of it.
@@ -1481,7 +1480,7 @@ pub fn LLVMRustPrintModule(PM: &PassManager<'a>,
     pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
 
-    pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: &mut *const c_char) -> size_t;
+    pub fn LLVMRustGetSectionName(SI: &SectionIterator, data: &mut *const c_char) -> size_t;
 
     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
 
index 93dd98c62dc3edd28afd61561218f4cfe4aa51a2..558d2a2bc87b363f634ccca1b2744f5709d42d4f 100644 (file)
@@ -204,19 +204,19 @@ fn drop(&mut self) {
 
 // Memory-managed interface to section iterators.
 
-pub struct SectionIter {
-    pub llsi: SectionIteratorRef,
+pub struct SectionIter<'a> {
+    pub llsi: &'a mut SectionIterator<'a>,
 }
 
-impl Drop for SectionIter {
+impl Drop for SectionIter<'a> {
     fn drop(&mut self) {
         unsafe {
-            LLVMDisposeSectionIterator(self.llsi);
+            LLVMDisposeSectionIterator(&mut *(self.llsi as *mut _));
         }
     }
 }
 
-pub fn mk_section_iter(llof: &ffi::ObjectFile) -> SectionIter {
+pub fn mk_section_iter(llof: &'a ffi::ObjectFile) -> SectionIter<'a> {
     unsafe { SectionIter { llsi: LLVMGetSections(llof) } }
 }