Skip to content

Commit 91aeff9

Browse files
committed
Add set_lang_name and Context::set_filename
1 parent f7c6a31 commit 91aeff9

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

gccjit_sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,4 +774,10 @@ extern_maybe_dlopen! {
774774

775775
#[cfg(feature="master")]
776776
fn gcc_jit_type_set_addressable(typ: *mut gcc_jit_type);
777+
778+
#[cfg(feature="master")]
779+
fn gcc_jit_set_lang_name(lang_name: *const c_char);
780+
781+
#[cfg(feature="master")]
782+
fn gcc_jit_context_set_filename(ctx: *mut gcc_jit_context, filename: *const c_char);
777783
}

src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,16 @@ impl<'ctx> Context<'ctx> {
12711271
panic!("{}", error);
12721272
}
12731273
}
1274+
1275+
#[cfg(feature="master")]
1276+
pub fn set_filename(&self, filename: &str) {
1277+
let c_str = CString::new(filename).unwrap();
1278+
with_lib(|lib| {
1279+
unsafe {
1280+
lib.gcc_jit_context_set_filename(self.ptr, c_str.as_ptr());
1281+
}
1282+
})
1283+
}
12741284
}
12751285

12761286
impl<'ctx> Drop for Context<'ctx> {

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod block;
3333
#[cfg(feature="master")]
3434
mod target_info;
3535

36-
#[cfg(feature="dlopen")]
36+
#[cfg(any(feature="dlopen", feature="master"))]
3737
use std::ffi::CStr;
3838
#[cfg(feature="dlopen")]
3939
use std::sync::OnceLock;
@@ -148,3 +148,12 @@ pub static LIB: OnceLock<Option<Libgccjit>> = OnceLock::new();
148148
// Without the dlopen feature, we avoid using OnceLock as to not have any performance impact.
149149
#[cfg(not(feature="dlopen"))]
150150
static LIB: Libgccjit = Libgccjit::new();
151+
152+
#[cfg(feature="master")]
153+
pub fn set_lang_name(lang_name: &'static CStr) {
154+
unsafe {
155+
with_lib(|lib| {
156+
lib.gcc_jit_set_lang_name(lang_name.as_ptr());
157+
});
158+
}
159+
}

0 commit comments

Comments
 (0)