change no_mangle
to unsafe(no_mangle)
This commit is contained in:
parent
718e574d3a
commit
581a1778ca
|
@ -32,12 +32,12 @@ mod panicking;
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
|
static ALLOCATOR: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_alloc(size: usize, align: usize) -> *mut u8 {
|
unsafe extern "C" fn haku_alloc(size: usize, align: usize) -> *mut u8 {
|
||||||
alloc::alloc::alloc(Layout::from_size_align(size, align).unwrap())
|
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) {
|
unsafe extern "C" fn haku_free(ptr: *mut u8, size: usize, align: usize) {
|
||||||
alloc::alloc::dealloc(ptr, Layout::from_size_align(size, align).unwrap())
|
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 {
|
extern "C" fn haku_limits_new() -> *mut Limits {
|
||||||
let ptr = Box::leak(Box::new(Limits::default())) as *mut _;
|
let ptr = Box::leak(Box::new(Limits::default())) as *mut _;
|
||||||
debug!("created limits: {ptr:?}");
|
debug!("created limits: {ptr:?}");
|
||||||
ptr
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_limits_destroy(limits: *mut Limits) {
|
unsafe extern "C" fn haku_limits_destroy(limits: *mut Limits) {
|
||||||
debug!("destroying limits: {limits:?}");
|
debug!("destroying limits: {limits:?}");
|
||||||
drop(Box::from_raw(limits))
|
drop(Box::from_raw(limits))
|
||||||
|
@ -99,7 +99,7 @@ unsafe extern "C" fn haku_limits_destroy(limits: *mut Limits) {
|
||||||
macro_rules! limit_setter {
|
macro_rules! limit_setter {
|
||||||
($name:tt) => {
|
($name:tt) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn [<haku_limits_set_ $name>](limits: *mut Limits, value: usize) {
|
unsafe extern "C" fn [<haku_limits_set_ $name>](limits: *mut Limits, value: usize) {
|
||||||
debug!("set limit {} = {value}", stringify!($name));
|
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 {
|
unsafe extern "C" fn haku_instance_new(limits: *const Limits) -> *mut Instance {
|
||||||
let limits = *limits;
|
let limits = *limits;
|
||||||
debug!("creating new instance with 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
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_instance_destroy(instance: *mut Instance) {
|
unsafe extern "C" fn haku_instance_destroy(instance: *mut Instance) {
|
||||||
debug!("destroying instance: {instance:?}");
|
debug!("destroying instance: {instance:?}");
|
||||||
drop(Box::from_raw(instance));
|
drop(Box::from_raw(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_reset(instance: *mut Instance) {
|
unsafe extern "C" fn haku_reset(instance: *mut Instance) {
|
||||||
debug!("resetting instance: {instance:?}");
|
debug!("resetting instance: {instance:?}");
|
||||||
let instance = &mut *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);
|
instance.defs.restore_image(&instance.defs_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_has_exception(instance: *mut Instance) -> bool {
|
unsafe extern "C" fn haku_has_exception(instance: *mut Instance) -> bool {
|
||||||
(*instance).exception.is_some()
|
(*instance).exception.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_exception_message(instance: *const Instance) -> *const u8 {
|
unsafe extern "C" fn haku_exception_message(instance: *const Instance) -> *const u8 {
|
||||||
(*instance).exception.as_ref().unwrap().message.as_ptr()
|
(*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 {
|
unsafe extern "C" fn haku_exception_message_len(instance: *const Instance) -> u32 {
|
||||||
(*instance).exception.as_ref().unwrap().message.len() as u32
|
(*instance).exception.as_ref().unwrap().message.len() as u32
|
||||||
}
|
}
|
||||||
|
@ -242,17 +242,17 @@ enum StatusCode {
|
||||||
RenderException,
|
RenderException,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn haku_is_ok(code: StatusCode) -> bool {
|
extern "C" fn haku_is_ok(code: StatusCode) -> bool {
|
||||||
code == StatusCode::Ok
|
code == StatusCode::Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn haku_is_diagnostics_emitted(code: StatusCode) -> bool {
|
extern "C" fn haku_is_diagnostics_emitted(code: StatusCode) -> bool {
|
||||||
code == StatusCode::DiagnosticsEmitted
|
code == StatusCode::DiagnosticsEmitted
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn haku_is_exception(code: StatusCode) -> bool {
|
extern "C" fn haku_is_exception(code: StatusCode) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
code,
|
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 {
|
extern "C" fn haku_status_string(code: StatusCode) -> *const i8 {
|
||||||
match code {
|
match code {
|
||||||
StatusCode::Ok => c"ok",
|
StatusCode::Ok => c"ok",
|
||||||
|
@ -292,45 +292,45 @@ struct Brush {
|
||||||
state: BrushState,
|
state: BrushState,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn haku_brush_new() -> *mut Brush {
|
extern "C" fn haku_brush_new() -> *mut Brush {
|
||||||
let ptr = Box::leak(Box::new(Brush::default())) as *mut _;
|
let ptr = Box::leak(Box::new(Brush::default())) as *mut _;
|
||||||
debug!("created brush: {ptr:?}");
|
debug!("created brush: {ptr:?}");
|
||||||
ptr
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_brush_destroy(brush: *mut Brush) {
|
unsafe extern "C" fn haku_brush_destroy(brush: *mut Brush) {
|
||||||
debug!("destroying brush: {brush:?}");
|
debug!("destroying brush: {brush:?}");
|
||||||
drop(Box::from_raw(brush))
|
drop(Box::from_raw(brush))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_num_diagnostics(brush: *const Brush) -> u32 {
|
unsafe extern "C" fn haku_num_diagnostics(brush: *const Brush) -> u32 {
|
||||||
(*brush).diagnostics.len() as u32
|
(*brush).diagnostics.len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_diagnostic_start(brush: *const Brush, index: u32) -> u32 {
|
unsafe extern "C" fn haku_diagnostic_start(brush: *const Brush, index: u32) -> u32 {
|
||||||
(*brush).diagnostics[index as usize].span().start
|
(*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 {
|
unsafe extern "C" fn haku_diagnostic_end(brush: *const Brush, index: u32) -> u32 {
|
||||||
(*brush).diagnostics[index as usize].span().end
|
(*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 {
|
unsafe extern "C" fn haku_diagnostic_message(brush: *const Brush, index: u32) -> *const u8 {
|
||||||
(*brush).diagnostics[index as usize].message().as_ptr()
|
(*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 {
|
unsafe extern "C" fn haku_diagnostic_message_len(brush: *const Brush, index: u32) -> u32 {
|
||||||
(*brush).diagnostics[index as usize].message().len() as u32
|
(*brush).diagnostics[index as usize].message().len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_compile_brush(
|
unsafe extern "C" fn haku_compile_brush(
|
||||||
instance: *mut Instance,
|
instance: *mut Instance,
|
||||||
out_brush: *mut Brush,
|
out_brush: *mut Brush,
|
||||||
|
@ -438,7 +438,7 @@ unsafe extern "C" fn haku_compile_brush(
|
||||||
StatusCode::Ok
|
StatusCode::Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn haku_pixmap_new(width: u32, height: u32) -> *mut Pixmap {
|
extern "C" fn haku_pixmap_new(width: u32, height: u32) -> *mut Pixmap {
|
||||||
let ptr = Box::leak(Box::new(
|
let ptr = Box::leak(Box::new(
|
||||||
Pixmap::new(width, height).expect("invalid pixmap size"),
|
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
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_pixmap_destroy(pixmap: *mut Pixmap) {
|
unsafe extern "C" fn haku_pixmap_destroy(pixmap: *mut Pixmap) {
|
||||||
debug!("destroying pixmap: {pixmap:?}");
|
debug!("destroying pixmap: {pixmap:?}");
|
||||||
drop(Box::from_raw(pixmap))
|
drop(Box::from_raw(pixmap))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_pixmap_data(pixmap: *mut Pixmap) -> *mut u8 {
|
unsafe extern "C" fn haku_pixmap_data(pixmap: *mut Pixmap) -> *mut u8 {
|
||||||
let pixmap = &mut *pixmap;
|
let pixmap = &mut *pixmap;
|
||||||
pixmap.pixels_mut().as_mut_ptr() as *mut u8
|
pixmap.pixels_mut().as_mut_ptr() as *mut u8
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_pixmap_clear(pixmap: *mut Pixmap) {
|
unsafe extern "C" fn haku_pixmap_clear(pixmap: *mut Pixmap) {
|
||||||
let pixmap = &mut *pixmap;
|
let pixmap = &mut *pixmap;
|
||||||
pixmap.pixels_mut().fill(PremultipliedColorU8::TRANSPARENT);
|
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 {
|
unsafe extern "C" fn haku_begin_brush(instance: *mut Instance, brush: *const Brush) -> StatusCode {
|
||||||
let instance = &mut *instance;
|
let instance = &mut *instance;
|
||||||
let brush = &*brush;
|
let brush = &*brush;
|
||||||
|
@ -499,7 +499,7 @@ unsafe extern "C" fn haku_begin_brush(instance: *mut Instance, brush: *const Bru
|
||||||
StatusCode::Ok
|
StatusCode::Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn haku_cont_kind(instance: *mut Instance) -> Cont {
|
unsafe extern "C" fn haku_cont_kind(instance: *mut Instance) -> Cont {
|
||||||
let instance = &mut *instance;
|
let instance = &mut *instance;
|
||||||
instance.trampoline.as_ref().unwrap().cont(&instance.vm)
|
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(
|
unsafe extern "C" fn haku_cont_scribble(
|
||||||
instance: *mut Instance,
|
instance: *mut Instance,
|
||||||
pixmap: *mut Pixmap,
|
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(
|
unsafe extern "C" fn haku_cont_dotter(
|
||||||
instance: *mut Instance,
|
instance: *mut Instance,
|
||||||
from_x: f32,
|
from_x: f32,
|
||||||
|
|
Loading…
Reference in a new issue