From 870506531b8dc1884eedf46fa968dd9cc27fd9b0 Mon Sep 17 00:00:00 2001 From: noname0310 Date: Wed, 21 Aug 2024 11:09:05 +0900 Subject: [PATCH] replace transmute to box from/into --- rust/plugin_wasm/src/model/c_api.rs | 9 ++------- rust/plugin_wasm/src/motion/c_api.rs | 9 ++------- rust/plugin_wasm_test_model_full/src/lib.rs | 4 ++-- rust/plugin_wasm_test_model_minimum/src/lib.rs | 4 ++-- rust/plugin_wasm_test_motion_full/src/lib.rs | 4 ++-- rust/plugin_wasm_test_motion_minimum/src/lib.rs | 4 ++-- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/rust/plugin_wasm/src/model/c_api.rs b/rust/plugin_wasm/src/model/c_api.rs index cc6cf55e..c3816d0b 100644 --- a/rust/plugin_wasm/src/model/c_api.rs +++ b/rust/plugin_wasm/src/model/c_api.rs @@ -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, - *mut nanoem_application_plugin_model_io_t, - >(plugin) - }; + return Box::into_raw(plugin); } } null_mut() @@ -738,7 +733,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy( plugin: *mut nanoem_application_plugin_model_io_t, ) { if !plugin.is_null() { - let _: Box = unsafe { std::mem::transmute(plugin) }; + let _ = unsafe { Box::from_raw(plugin) }; } } diff --git a/rust/plugin_wasm/src/motion/c_api.rs b/rust/plugin_wasm/src/motion/c_api.rs index e2f9454f..93f08491 100644 --- a/rust/plugin_wasm/src/motion/c_api.rs +++ b/rust/plugin_wasm/src/motion/c_api.rs @@ -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, - *mut nanoem_application_plugin_motion_io_t, - >(plugin) - }; + return Box::into_raw(plugin); } } null_mut() @@ -719,7 +714,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy( plugin: *mut nanoem_application_plugin_motion_io_t, ) { if !plugin.is_null() { - let _: Box = unsafe { std::mem::transmute(plugin) }; + let _ = unsafe { Box::from_raw(plugin) }; } } diff --git a/rust/plugin_wasm_test_model_full/src/lib.rs b/rust/plugin_wasm_test_model_full/src/lib.rs index a0275585..38444d58 100644 --- a/rust/plugin_wasm_test_model_full/src/lib.rs +++ b/rust/plugin_wasm_test_model_full/src/lib.rs @@ -97,7 +97,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreate( .unwrap() ); let plugin = Box::::default(); - std::mem::transmute(plugin) + Box::into_raw(plugin) } /// # Safety @@ -804,7 +804,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy( .unwrap() ); if !plugin.is_null() { - let _: Box = std::mem::transmute(plugin); + let _ = unsafe { Box::from_raw(plugin) }; } } diff --git a/rust/plugin_wasm_test_model_minimum/src/lib.rs b/rust/plugin_wasm_test_model_minimum/src/lib.rs index 31d462d0..02fa82d2 100644 --- a/rust/plugin_wasm_test_model_minimum/src/lib.rs +++ b/rust/plugin_wasm_test_model_minimum/src/lib.rs @@ -67,7 +67,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIOCreate( .unwrap() ); let plugin = Box::::default(); - std::mem::transmute(plugin) + Box::into_raw(plugin) } /// # Safety @@ -319,7 +319,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginModelIODestroy( .unwrap() ); if !plugin.is_null() { - let _: Box = std::mem::transmute(plugin); + let _ = unsafe { Box::from_raw(plugin) }; } } diff --git a/rust/plugin_wasm_test_motion_full/src/lib.rs b/rust/plugin_wasm_test_motion_full/src/lib.rs index 42112f97..f3a7ebe8 100644 --- a/rust/plugin_wasm_test_motion_full/src/lib.rs +++ b/rust/plugin_wasm_test_motion_full/src/lib.rs @@ -97,7 +97,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreate( .unwrap() ); let plugin = Box::::default(); - std::mem::transmute(plugin) + Box::into_raw(plugin) } /// # Safety @@ -785,7 +785,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy( .unwrap() ); if !plugin.is_null() { - let _: Box = std::mem::transmute(plugin); + let _ = unsafe { Box::from_raw(plugin) }; } } diff --git a/rust/plugin_wasm_test_motion_minimum/src/lib.rs b/rust/plugin_wasm_test_motion_minimum/src/lib.rs index 81d85753..b8766754 100644 --- a/rust/plugin_wasm_test_motion_minimum/src/lib.rs +++ b/rust/plugin_wasm_test_motion_minimum/src/lib.rs @@ -67,7 +67,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIOCreate( .unwrap() ); let plugin = Box::::default(); - std::mem::transmute(plugin) + Box::into_raw(plugin) } /// # Safety @@ -337,7 +337,7 @@ pub unsafe extern "C" fn nanoemApplicationPluginMotionIODestroy( .unwrap() ); if !plugin.is_null() { - let _: Box = std::mem::transmute(plugin); + let _ = unsafe { Box::from_raw(plugin) }; } }