about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrina Popa <irinagpopa@gmail.com>2018-07-17 14:22:02 +0300
committerIrina Popa <irinagpopa@gmail.com>2018-07-30 20:10:39 +0300
commit2c1d7fbb8373321d043f4658f310c0b869124cdc (patch)
tree33a387612c8a7c079e1223060b8fa822def80755
parente22eebaf2b1b59c3eed52bd5621c63123af654ad (diff)
downloadrust-2c1d7fbb8373321d043f4658f310c0b869124cdc.tar.gz
rust-2c1d7fbb8373321d043f4658f310c0b869124cdc.zip
rustc_codegen_llvm: use safe references for SectionIterator.
-rw-r--r--src/librustc_codegen_llvm/llvm/ffi.rs17
-rw-r--r--src/librustc_codegen_llvm/llvm/mod.rs10
2 files changed, 13 insertions, 14 deletions
diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs
index 7883315a5de..4b1e8e06261 100644
--- a/src/librustc_codegen_llvm/llvm/ffi.rs
+++ b/src/librustc_codegen_llvm/llvm/ffi.rs
@@ -400,8 +400,7 @@ extern { pub type MemoryBuffer; }
 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 @@ extern "C" {
     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 @@ extern "C" {
     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);
 
diff --git a/src/librustc_codegen_llvm/llvm/mod.rs b/src/librustc_codegen_llvm/llvm/mod.rs
index 93dd98c62dc..558d2a2bc87 100644
--- a/src/librustc_codegen_llvm/llvm/mod.rs
+++ b/src/librustc_codegen_llvm/llvm/mod.rs
@@ -204,19 +204,19 @@ impl Drop for ObjectFile {
 
 // 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) } }
 }