From 12a16b77e26ad952de034962c709785ae1b1a03e Mon Sep 17 00:00:00 2001 From: subkey <2822448396@qq.com> Date: Wed, 17 Apr 2024 04:16:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=AF=8F=E5=A4=A9=E9=83=BD=E5=9C=A8?= =?UTF-8?q?=E4=BF=AEoutlive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/helloworld.ks | 13 ++++++------- src/runtime/outlive.rs | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/samples/helloworld.ks b/samples/helloworld.ks index 7dae7a5..7d55808 100644 --- a/samples/helloworld.ks +++ b/samples/helloworld.ks @@ -1,11 +1,10 @@ //mod D:\code\rs\tst\target\debug\tstlib.dll> m; -let a() { - try throw (299) - catch e { - :e - } -} -log(a()) +let a = 5; +let f1() { + let a = 20; + :||:a // 相当于return (||return a) +} +log(f1()()) // 20 diff --git a/src/runtime/outlive.rs b/src/runtime/outlive.rs index 4deaeec..37c0cb9 100644 --- a/src/runtime/outlive.rs +++ b/src/runtime/outlive.rs @@ -85,11 +85,13 @@ pub fn decrease_scope_count(mut scope: Scope) { loop { let prev = scope.outlives.fetch_sub(1, Ordering::Relaxed); + let parent = scope.parent; if prev == 1 && scope.ended { // println!("{:02}: scope drop by func: {:p}",ln(), scope.ptr); unsafe{ std::ptr::drop_in_place(scope.ptr) } + scope.ptr = std::ptr::null_mut(); } - if let Some(prt) = scope.parent { + if let Some(prt) = parent { scope = prt; }else { break;