mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
rustc_codegen_llvm: use safe references for Archive.
This commit is contained in:
parent
0e3a705269
commit
41d7d8e35e
@ -10,8 +10,6 @@
|
||||
|
||||
//! A wrapper around LLVM's archive (.a) code
|
||||
|
||||
use super::ArchiveRef;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::marker;
|
||||
use std::path::Path;
|
||||
@ -19,7 +17,7 @@ use std::slice;
|
||||
use std::str;
|
||||
|
||||
pub struct ArchiveRO {
|
||||
ptr: ArchiveRef,
|
||||
raw: &'static mut super::Archive,
|
||||
}
|
||||
|
||||
unsafe impl Send for ArchiveRO {}
|
||||
@ -44,12 +42,9 @@ impl ArchiveRO {
|
||||
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
|
||||
return unsafe {
|
||||
let s = path2cstr(dst);
|
||||
let ar = super::LLVMRustOpenArchive(s.as_ptr());
|
||||
if ar.is_null() {
|
||||
Err(super::last_error().unwrap_or("failed to open archive".to_string()))
|
||||
} else {
|
||||
Ok(ArchiveRO { ptr: ar })
|
||||
}
|
||||
let ar = super::LLVMRustOpenArchive(s.as_ptr())
|
||||
.ok_or_else(|| super::last_error().unwrap_or("failed to open archive".to_string()))?;
|
||||
Ok(ArchiveRO { raw: ar })
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
@ -65,14 +60,14 @@ impl ArchiveRO {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> ArchiveRef {
|
||||
self.ptr
|
||||
pub fn raw(&self) -> &super::Archive {
|
||||
self.raw
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> Iter {
|
||||
unsafe {
|
||||
Iter {
|
||||
ptr: super::LLVMRustArchiveIteratorNew(self.ptr),
|
||||
ptr: super::LLVMRustArchiveIteratorNew(self.raw),
|
||||
_data: marker::PhantomData,
|
||||
}
|
||||
}
|
||||
@ -82,7 +77,7 @@ impl ArchiveRO {
|
||||
impl Drop for ArchiveRO {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
super::LLVMRustDestroyArchive(self.ptr);
|
||||
super::LLVMRustDestroyArchive(&mut *(self.raw as *mut _));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -399,7 +399,6 @@ pub type SectionIteratorRef = *mut SectionIterator;
|
||||
extern { pub type Pass; }
|
||||
extern { pub type TargetMachine; }
|
||||
extern { pub type Archive; }
|
||||
pub type ArchiveRef = *mut Archive;
|
||||
extern { pub type ArchiveIterator; }
|
||||
pub type ArchiveIteratorRef = *mut ArchiveIterator;
|
||||
extern { pub type ArchiveChild; }
|
||||
@ -1471,14 +1470,14 @@ extern "C" {
|
||||
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
|
||||
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
|
||||
|
||||
pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
|
||||
pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
|
||||
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 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 LLVMRustDestroyArchive(AR: ArchiveRef);
|
||||
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
|
||||
|
||||
pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: *mut *const c_char) -> size_t;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user