Skip to content

Commit

Permalink
replace transmute to box from/into
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0310 committed Aug 21, 2024
1 parent faa0f70 commit 8705065
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
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

0 comments on commit 8705065

Please sign in to comment.