//! A wrapper around LLVM's archive (.a) code
-use super::ArchiveRef;
-
use std::ffi::CString;
use std::marker;
use std::path::Path;
use std::str;
pub struct ArchiveRO {
- ptr: ArchiveRef,
+ raw: &'static mut super::Archive,
}
unsafe impl Send for 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)]
}
}
- 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,
}
}
impl Drop for ArchiveRO {
fn drop(&mut self) {
unsafe {
- super::LLVMRustDestroyArchive(self.ptr);
+ super::LLVMRustDestroyArchive(&mut *(self.raw as *mut _));
}
}
}
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; }
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;