rustc_codegen_llvm: use safe references for OperandBundleDef.
This commit is contained in:
parent
92af9694b9
commit
0ab3444540
4 changed files with 26 additions and 25 deletions
|
@ -258,28 +258,24 @@ pub fn last_error() -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct OperandBundleDef {
|
||||
inner: OperandBundleDefRef,
|
||||
pub struct OperandBundleDef<'a> {
|
||||
pub raw: &'a mut ffi::OperandBundleDef<'a>,
|
||||
}
|
||||
|
||||
impl OperandBundleDef {
|
||||
pub fn new(name: &str, vals: &[&'a Value]) -> OperandBundleDef {
|
||||
impl OperandBundleDef<'a> {
|
||||
pub fn new(name: &str, vals: &[&'a Value]) -> Self {
|
||||
let name = CString::new(name).unwrap();
|
||||
let def = unsafe {
|
||||
LLVMRustBuildOperandBundleDef(name.as_ptr(), vals.as_ptr(), vals.len() as c_uint)
|
||||
};
|
||||
OperandBundleDef { inner: def }
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> OperandBundleDefRef {
|
||||
self.inner
|
||||
OperandBundleDef { raw: def }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for OperandBundleDef {
|
||||
impl Drop for OperandBundleDef<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
LLVMRustFreeOperandBundleDef(self.inner);
|
||||
LLVMRustFreeOperandBundleDef(&mut *(self.raw as *mut _));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue