Skip to content
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

Replace transmute to box from/into #503

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions rust/plugin_wasm/src/model/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreateWithLocation(
let result = instance.create();
if result.is_ok() {
let plugin = Box::new(instance);
return unsafe {
std::mem::transmute::<
Box<nanoem_application_plugin_model_io_t>,
*mut nanoem_application_plugin_model_io_t,
>(plugin)
};
return Box::into_raw(plugin);
}
}
null_mut()
Expand Down Expand Up @@ -738,7 +733,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy(
plugin: *mut nanoem_application_plugin_model_io_t,
) {
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_model_io_t> = unsafe { std::mem::transmute(plugin) };
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down
9 changes: 2 additions & 7 deletions rust/plugin_wasm/src/motion/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreateWithLocation(
let result = instance.create();
if result.is_ok() {
let plugin = Box::new(instance);
return unsafe {
std::mem::transmute::<
Box<nanoem_application_plugin_motion_io_t>,
*mut nanoem_application_plugin_motion_io_t,
>(plugin)
};
return Box::into_raw(plugin);
}
}
null_mut()
Expand Down Expand Up @@ -719,7 +714,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy(
plugin: *mut nanoem_application_plugin_motion_io_t,
) {
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_motion_io_t> = unsafe { std::mem::transmute(plugin) };
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/plugin_wasm_test_model_full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreate(
.unwrap()
);
let plugin = Box::<nanoem_application_plugin_model_io_t>::default();
std::mem::transmute(plugin)
Box::into_raw(plugin)
}

/// # Safety
Expand Down Expand Up @@ -804,7 +804,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy(
.unwrap()
);
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_model_io_t> = std::mem::transmute(plugin);
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/plugin_wasm_test_model_minimum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreate(
.unwrap()
);
let plugin = Box::<nanoem_application_plugin_model_io_t>::default();
std::mem::transmute(plugin)
Box::into_raw(plugin)
}

/// # Safety
Expand Down Expand Up @@ -319,7 +319,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy(
.unwrap()
);
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_model_io_t> = std::mem::transmute(plugin);
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/plugin_wasm_test_motion_full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreate(
.unwrap()
);
let plugin = Box::<nanoem_application_plugin_motion_io_t>::default();
std::mem::transmute(plugin)
Box::into_raw(plugin)
}

/// # Safety
Expand Down Expand Up @@ -785,7 +785,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy(
.unwrap()
);
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_motion_io_t> = std::mem::transmute(plugin);
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/plugin_wasm_test_motion_minimum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreate(
.unwrap()
);
let plugin = Box::<nanoem_application_plugin_motion_io_t>::default();
std::mem::transmute(plugin)
Box::into_raw(plugin)
}

/// # Safety
Expand Down Expand Up @@ -337,7 +337,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy(
.unwrap()
);
if !plugin.is_null() {
let _: Box<nanoem_application_plugin_motion_io_t> = std::mem::transmute(plugin);
let _ = unsafe { Box::from_raw(plugin) };
}
}

Expand Down