ソースを参照

refactor & feat: 调整run-code释放机制

SongZihuan 3 年 前
コミット
c437bee8c0
3 ファイル変更28 行追加18 行削除
  1. 22 16
      test/src/run-code.cpp
  2. 3 1
      test/src/tool-exit.cpp
  3. 3 1
      test/src/tool-logger.cpp

+ 22 - 16
test/src/run-code.cpp

@@ -259,24 +259,30 @@ int Main() {
 }
 
 int main() {
-    std::string base_path = getExedir(1);
-    if (base_path.empty()) {
-        printf_stderr(0, "aFunlang init error.");
-        aFunExitReal(EXIT_FAILURE);
-    }
+    int exit_code = 0;
+    try {
+        std::string base_path = getExedir(1);
+        if (base_path.empty()) {
+            printf_stderr(0, "aFunlang init error.");
+            aFunExitReal(EXIT_FAILURE);
+        }
 
-    aFuntool::LogFactory factor {};
-    aFuncore::InitInfo info = {.base_dir=base_path,
-                               .factor=factor,
-                               .log_asyn=true,
-                               .level=log_debug,
-    };
+        aFuntool::LogFactory factor{};
+        aFuncore::InitInfo info = {.base_dir=base_path,
+            .factor=factor,
+            .log_asyn=true,
+            .level=log_debug,
+        };
 
-    if (!aFunCoreInit(&info)) {
-        printf_stderr(0, "aFunlang init error.");
-        aFunExitReal(EXIT_FAILURE);
-    }
+        if (!aFunCoreInit(&info)) {
+            printf_stderr(0, "aFunlang init error.");
+            aFunExitReal(EXIT_FAILURE);
+        }
 
-    int exit_code = Main();
+        exit_code = Main();
+        aFunExit(exit_code);
+    } catch (aFuntool::Exit &e) {
+        exit_code = e.getExitCode();
+    }
     aFunExitReal(exit_code);
 }

+ 3 - 1
test/src/tool-exit.cpp

@@ -11,11 +11,13 @@ void exit_func_push2(void *) {
 }
 
 int main(int argc, char **argv) {
+    int exit_code = 0;
     try {
         aFunAtExit(exit_func_push1, nullptr);
         aFunAtExit(exit_func_push2, nullptr);
         aFunExit(0);
     } catch (aFuntool::Exit &e) {
-        aFunExitReal(e.getExitCode());
+        exit_code = e.getExitCode();
     }
+    aFunExitReal(exit_code);
 }

+ 3 - 1
test/src/tool-logger.cpp

@@ -2,6 +2,7 @@
 using namespace aFuntool;
 
 int main(int argc, char **argv){
+    int exit_code = 0;
     try {
         std::string base_path = getExedir(1);
         if (base_path.empty()) {
@@ -18,6 +19,7 @@ int main(int argc, char **argv){
         infoLog(&logger, "Test logger");
         aFunExit(0);
     } catch (aFuntool::Exit &e) {
-        aFunExitReal(e.getExitCode());
+        exit_code = e.getExitCode();
     }
+    aFunExitReal(exit_code);
 }