Skip to content

Add binding for new gcc_jit_lvalue_get_name function #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gccjit_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,4 +699,7 @@ extern "C" {

#[cfg(feature="master")]
pub fn gcc_jit_lvalue_add_attribute(variable: *mut gcc_jit_lvalue, attribute: gcc_jit_variable_attribute);

#[cfg(feature="master")]
pub fn gcc_jit_lvalue_get_name(lvalue: *mut gcc_jit_lvalue) -> *const c_char;
}
13 changes: 13 additions & 0 deletions src/lvalue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{ffi::CString, marker::PhantomData};
use std::fmt;
use std::ptr;

use context::Context;
use rvalue::{RValue, ToRValue};
use rvalue;
Expand Down Expand Up @@ -238,6 +239,18 @@ impl<'ctx> LValue<'ctx> {
},
}
}

#[cfg(feature = "master")]
pub fn get_name(&self) -> Option<&'ctx str> {
unsafe {
let str = gccjit_sys::gcc_jit_lvalue_get_name(self.ptr);
if str.is_null() {
None
} else {
Some(std::ffi::CStr::from_ptr(str).to_str().expect("invalid lvalue name"))
}
}
}
}

pub unsafe fn from_ptr<'ctx>(ptr: *mut gccjit_sys::gcc_jit_lvalue) -> LValue<'ctx> {
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'ctx> Type<'ctx> {
pub fn get_size(&self) -> u32 {
unsafe {
let size = gccjit_sys::gcc_jit_type_get_size(self.ptr);
assert_ne!(size, -1, "called get_size of unsupported type: {:?}", self);
assert_ne!(size, -1, "called get_size of unsupported type: {self:?}");
size as u32
}
}
Expand Down
Loading