From 940afb044d47972d0784e9c7b1f534923e0b94bb Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Tue, 16 Jan 2024 10:49:28 -0600 Subject: [PATCH] fix init and post upgrade method calls --- examples/init/src/index.did | 10 +++------- src/compiler/rust/canister_methods/src/lib.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/init/src/index.did b/examples/init/src/index.did index cc7375fed2..4f448d1dba 100644 --- a/examples/init/src/index.did +++ b/examples/init/src/index.did @@ -1,9 +1,5 @@ -type rec_0 = record {id:text}; -type rec_1 = variant {Fire; Wave}; -type rec_2 = record {id:text}; -type rec_3 = variant {Fire; Wave}; -service: (rec_0, rec_1, principal) -> { - getUser: () -> (opt rec_2) query; - getReaction: () -> (opt rec_3) query; +service: (record {id:text}, variant {Fire; Wave}, principal) -> { getOwner: () -> (opt principal) query; + getReaction: () -> (opt variant {Fire; Wave}) query; + getUser: () -> (opt record {id:text}) query; } diff --git a/src/compiler/rust/canister_methods/src/lib.rs b/src/compiler/rust/canister_methods/src/lib.rs index 7c9b9f4bc9..9028721c3f 100644 --- a/src/compiler/rust/canister_methods/src/lib.rs +++ b/src/compiler/rust/canister_methods/src/lib.rs @@ -54,7 +54,7 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { let init_method = quote! { #[ic_cdk_macros::init] fn init() { - unsafe { ic_wasi_polyfill::init(&[], &[]); } + ic_wasi_polyfill::init(&[], &[]); let mut rt = wasmedge_quickjs::Runtime::new(); @@ -74,8 +74,6 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { // }; // ic_cdk::println!("temp: {:#?}", temp); - - #init_method_call }); ic_cdk::println!("init result: {:#?}", r); @@ -84,6 +82,8 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { let mut runtime = runtime.borrow_mut(); *runtime = Some(rt); }); + + #init_method_call } }; @@ -100,7 +100,7 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { let post_update_method = quote! { #[ic_cdk_macros::post_upgrade] fn post_upgrade() { - unsafe { ic_wasi_polyfill::init(&[], &[]); } + ic_wasi_polyfill::init(&[], &[]); let mut rt = wasmedge_quickjs::Runtime::new(); @@ -120,8 +120,6 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { // }; // ic_cdk::println!("temp: {:#?}", temp); - - #post_update_method_call }); ic_cdk::println!("post_upgrade result: {:#?}", r); @@ -130,6 +128,8 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { let mut runtime = runtime.borrow_mut(); *runtime = Some(rt); }); + + #post_update_method_call } };