[Rust] fix #6205 (#6207)
author韩朴宇 <w12101111@gmail.com>
Wed, 5 Aug 2020 02:32:26 +0000 (10:32 +0800)
committerGitHub <noreply@github.com>
Wed, 5 Aug 2020 02:32:26 +0000 (19:32 -0700)
rust/tvm-sys/src/byte_array.rs
rust/tvm-sys/src/packed_func.rs
rust/tvm/examples/resnet/src/main.rs

index ea2feeb..0f02771 100644 (file)
@@ -72,10 +72,9 @@ impl<T: AsRef<[u8]>> From<T> for ByteArray {
     }
 }
 
-impl From<ByteArray> for ArgValue<'static> {
-    fn from(val: ByteArray) -> ArgValue<'static> {
-        // TODO(@jroesch): brorowed ArgValue are not sound
-        ArgValue::Bytes(unsafe { std::mem::transmute(&val.array) })
+impl<'a> From<&'a ByteArray> for ArgValue<'a> {
+    fn from(val: &'a ByteArray) -> ArgValue<'a> {
+        ArgValue::Bytes(&val.array)
     }
 }
 
index b1e2af9..3121deb 100644 (file)
@@ -161,7 +161,7 @@ TVMPODValue! {
     },
     match &self {
         Bytes(val) => {
-            (TVMValue { v_handle: val as *const _ as *mut c_void }, TVMArgTypeCode_kTVMBytes)
+            (TVMValue { v_handle: *val as *const _ as *mut c_void }, TVMArgTypeCode_kTVMBytes)
         }
         Str(val) => { (TVMValue { v_handle: val.as_ptr() as *mut c_void }, TVMArgTypeCode_kTVMStr) }
     }
index c81087d..16ca8c7 100644 (file)
@@ -91,7 +91,7 @@ fn main() {
         fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/deploy_param.params")).unwrap();
     let barr = ByteArray::from(&params);
     // load the parameters
-    load_param_fn.invoke(vec![barr.into()]).unwrap();
+    load_param_fn.invoke(vec![(&barr).into()]).unwrap();
     // get the set_input function
     let ref set_input_fn = graph_runtime_module
         .get_function("set_input", false)