From 581a1778caf9d0f5f89f207d25fca6d60b881e96 Mon Sep 17 00:00:00 2001 From: liquidev Date: Wed, 23 Oct 2024 21:45:11 +0200 Subject: [PATCH] change `no_mangle` to `unsafe(no_mangle)` --- crates/haku-wasm/src/lib.rs | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/haku-wasm/src/lib.rs b/crates/haku-wasm/src/lib.rs index 29dff6a..b45e065 100644 --- a/crates/haku-wasm/src/lib.rs +++ b/crates/haku-wasm/src/lib.rs @@ -32,12 +32,12 @@ mod panicking; #[global_allocator] static ALLOCATOR: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_alloc(size: usize, align: usize) -> *mut u8 { alloc::alloc::alloc(Layout::from_size_align(size, align).unwrap()) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_free(ptr: *mut u8, size: usize, align: usize) { alloc::alloc::dealloc(ptr, Layout::from_size_align(size, align).unwrap()) } @@ -83,14 +83,14 @@ impl Default for Limits { } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_limits_new() -> *mut Limits { let ptr = Box::leak(Box::new(Limits::default())) as *mut _; debug!("created limits: {ptr:?}"); ptr } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_limits_destroy(limits: *mut Limits) { debug!("destroying limits: {limits:?}"); drop(Box::from_raw(limits)) @@ -99,7 +99,7 @@ unsafe extern "C" fn haku_limits_destroy(limits: *mut Limits) { macro_rules! limit_setter { ($name:tt) => { paste::paste! { - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn [](limits: *mut Limits, value: usize) { debug!("set limit {} = {value}", stringify!($name)); @@ -153,7 +153,7 @@ impl Instance { } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_instance_new(limits: *const Limits) -> *mut Instance { let limits = *limits; debug!("creating new instance with limits: {limits:?}"); @@ -196,13 +196,13 @@ unsafe extern "C" fn haku_instance_new(limits: *const Limits) -> *mut Instance { ptr } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_instance_destroy(instance: *mut Instance) { debug!("destroying instance: {instance:?}"); drop(Box::from_raw(instance)); } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_reset(instance: *mut Instance) { debug!("resetting instance: {instance:?}"); let instance = &mut *instance; @@ -210,17 +210,17 @@ unsafe extern "C" fn haku_reset(instance: *mut Instance) { instance.defs.restore_image(&instance.defs_image); } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_has_exception(instance: *mut Instance) -> bool { (*instance).exception.is_some() } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_exception_message(instance: *const Instance) -> *const u8 { (*instance).exception.as_ref().unwrap().message.as_ptr() } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_exception_message_len(instance: *const Instance) -> u32 { (*instance).exception.as_ref().unwrap().message.len() as u32 } @@ -242,17 +242,17 @@ enum StatusCode { RenderException, } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_is_ok(code: StatusCode) -> bool { code == StatusCode::Ok } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_is_diagnostics_emitted(code: StatusCode) -> bool { code == StatusCode::DiagnosticsEmitted } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_is_exception(code: StatusCode) -> bool { matches!( code, @@ -260,7 +260,7 @@ extern "C" fn haku_is_exception(code: StatusCode) -> bool { ) } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_status_string(code: StatusCode) -> *const i8 { match code { StatusCode::Ok => c"ok", @@ -292,45 +292,45 @@ struct Brush { state: BrushState, } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_brush_new() -> *mut Brush { let ptr = Box::leak(Box::new(Brush::default())) as *mut _; debug!("created brush: {ptr:?}"); ptr } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_brush_destroy(brush: *mut Brush) { debug!("destroying brush: {brush:?}"); drop(Box::from_raw(brush)) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_num_diagnostics(brush: *const Brush) -> u32 { (*brush).diagnostics.len() as u32 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_diagnostic_start(brush: *const Brush, index: u32) -> u32 { (*brush).diagnostics[index as usize].span().start } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_diagnostic_end(brush: *const Brush, index: u32) -> u32 { (*brush).diagnostics[index as usize].span().end } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_diagnostic_message(brush: *const Brush, index: u32) -> *const u8 { (*brush).diagnostics[index as usize].message().as_ptr() } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_diagnostic_message_len(brush: *const Brush, index: u32) -> u32 { (*brush).diagnostics[index as usize].message().len() as u32 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_compile_brush( instance: *mut Instance, out_brush: *mut Brush, @@ -438,7 +438,7 @@ unsafe extern "C" fn haku_compile_brush( StatusCode::Ok } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn haku_pixmap_new(width: u32, height: u32) -> *mut Pixmap { let ptr = Box::leak(Box::new( Pixmap::new(width, height).expect("invalid pixmap size"), @@ -447,25 +447,25 @@ extern "C" fn haku_pixmap_new(width: u32, height: u32) -> *mut Pixmap { ptr } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_pixmap_destroy(pixmap: *mut Pixmap) { debug!("destroying pixmap: {pixmap:?}"); drop(Box::from_raw(pixmap)) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_pixmap_data(pixmap: *mut Pixmap) -> *mut u8 { let pixmap = &mut *pixmap; pixmap.pixels_mut().as_mut_ptr() as *mut u8 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_pixmap_clear(pixmap: *mut Pixmap) { let pixmap = &mut *pixmap; pixmap.pixels_mut().fill(PremultipliedColorU8::TRANSPARENT); } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_begin_brush(instance: *mut Instance, brush: *const Brush) -> StatusCode { let instance = &mut *instance; let brush = &*brush; @@ -499,7 +499,7 @@ unsafe extern "C" fn haku_begin_brush(instance: *mut Instance, brush: *const Bru StatusCode::Ok } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_cont_kind(instance: *mut Instance) -> Cont { let instance = &mut *instance; instance.trampoline.as_ref().unwrap().cont(&instance.vm) @@ -519,7 +519,7 @@ fn wrap_exception( } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_cont_scribble( instance: *mut Instance, pixmap: *mut Pixmap, @@ -547,7 +547,7 @@ unsafe extern "C" fn haku_cont_scribble( }) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn haku_cont_dotter( instance: *mut Instance, from_x: f32,