Skip to content

Commit a1bd437

Browse files
authored
Merge pull request #54 from GuillaumeGomez/gcc_jit_lvalue_get_name
Add binding for new `gcc_jit_lvalue_get_name` function
2 parents d57a079 + de3329f commit a1bd437

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

gccjit_sys/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,4 +699,7 @@ extern "C" {
699699

700700
#[cfg(feature="master")]
701701
pub fn gcc_jit_lvalue_add_attribute(variable: *mut gcc_jit_lvalue, attribute: gcc_jit_variable_attribute);
702+
703+
#[cfg(feature="master")]
704+
pub fn gcc_jit_lvalue_get_name(lvalue: *mut gcc_jit_lvalue) -> *const c_char;
702705
}

src/lvalue.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{ffi::CString, marker::PhantomData};
22
use std::fmt;
33
use std::ptr;
4+
45
use context::Context;
56
use rvalue::{RValue, ToRValue};
67
use rvalue;
@@ -238,6 +239,18 @@ impl<'ctx> LValue<'ctx> {
238239
},
239240
}
240241
}
242+
243+
#[cfg(feature = "master")]
244+
pub fn get_name(&self) -> Option<&'ctx str> {
245+
unsafe {
246+
let str = gccjit_sys::gcc_jit_lvalue_get_name(self.ptr);
247+
if str.is_null() {
248+
None
249+
} else {
250+
Some(std::ffi::CStr::from_ptr(str).to_str().expect("invalid lvalue name"))
251+
}
252+
}
253+
}
241254
}
242255

243256
pub unsafe fn from_ptr<'ctx>(ptr: *mut gccjit_sys::gcc_jit_lvalue) -> LValue<'ctx> {

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'ctx> Type<'ctx> {
212212
pub fn get_size(&self) -> u32 {
213213
unsafe {
214214
let size = gccjit_sys::gcc_jit_type_get_size(self.ptr);
215-
assert_ne!(size, -1, "called get_size of unsupported type: {:?}", self);
215+
assert_ne!(size, -1, "called get_size of unsupported type: {self:?}");
216216
size as u32
217217
}
218218
}

0 commit comments

Comments
 (0)