瀏覽代碼

fix: 修复vs编译运行问题

SongZihuan 3 年之前
父節點
當前提交
79b4a670e9
共有 11 個文件被更改,包括 46 次插入75 次删除
  1. 1 0
      include/main.h
  2. 1 0
      include/tool/path.h
  3. 1 0
      include/tool/stdio_.h
  4. 0 6
      include/tool/time_s.h
  5. 0 1
      src/core/__env.h
  6. 10 8
      src/core/env.c
  7. 0 1
      src/core/gc.c
  8. 1 3
      src/core/sig.c
  9. 4 2
      src/core/thread.c
  10. 2 2
      src/tool/file.c
  11. 26 52
      test/src/run_code.c

+ 1 - 0
include/main.h

@@ -1,5 +1,6 @@
 #ifndef AFUN_MAIN_H
 #define AFUN_MAIN_H
+#include "base.h"
 
 #ifdef aFunWIN32_NO_CYGWIN
 #include <io.h>

+ 1 - 0
include/tool/path.h

@@ -1,5 +1,6 @@
 #ifndef AFUN_PATH_H
 #define AFUN_PATH_H
+#include "base.h"
 
 /* 路径工具 */
 #ifdef aFunWIN32_NO_CYGWIN

+ 1 - 0
include/tool/stdio_.h

@@ -1,6 +1,7 @@
 #ifndef AFUN_STDIO__H
 #define AFUN_STDIO__H
 #include <stdio.h>
+#include "base.h"
 
 AFUN_TOOL_EXPORT int fgets_stdin(char **dest, int len);
 AFUN_TOOL_EXPORT bool checkStdin(void);

+ 0 - 6
include/tool/time_s.h

@@ -2,12 +2,6 @@
 #define AFUN_TIME_H
 #include "aFunToolExport.h"
 
-#ifdef aFunWin32
-
-#else
-#include <unistd.h>
-#endif
-
 /* 时间工具 */
 AFUN_TOOL_EXPORT void safeSleep(double ms);
 AFUN_TOOL_EXPORT char *getTime(time_t *t, char *format);

+ 0 - 1
src/core/__env.h

@@ -219,7 +219,6 @@ struct af_Environment {  // 运行环境
     bool all_exit;  // 由线程自己控制, 用于通知子线程退出
     bool son_exit;  // 由线程外部控制, 命令线程结束
     pthread_mutex_t thread_lock;  // 保护 father_exit 和 son_exit 和 son_count
-    pthread_cond_t thread_cond;  // 当次线程结束时就发起该条件
 
     enum af_CoreStatus {
         core_creat = 0,

+ 10 - 8
src/core/env.c

@@ -178,7 +178,7 @@ void setCoreExitNotExitCode(af_Environment *env) {
                 pthread_cond_signal(&envl->env->monitor->cond);
             pthread_mutex_unlock(&envl->env->thread_lock);
         }
-        pthread_mutex_lock(&env->thread_lock);
+        pthread_mutex_unlock(&env->thread_lock);
     }
 }
 
@@ -1713,12 +1713,12 @@ static bool freeEnvironmentList(af_EnvironmentList *envl, af_Environment *base)
     free(envl);
 
     pthread_mutex_unlock(&base->thread_lock);
-    pthread_cond_signal(&base->thread_cond);  // 通知主线程
     return true;
 }
 
 bool freeEnvironmentListByEnv(af_Environment *env, af_Environment *base) {
     pthread_mutex_lock(&base->thread_lock);
+
     for (af_EnvironmentList *envl = base->env_list; envl != NULL; envl = envl->next) {
         if (envl->env == env) {
             pthread_mutex_unlock(&base->thread_lock);
@@ -2230,11 +2230,13 @@ void waitForEnviromentExit(af_Environment *env) {
     pthread_mutex_unlock(&env->status_lock);
 
     if (env->gc_env != NULL)
-        setEnviromentExit_out(env->gc_env);
+        setEnviromentExit_out(env->gc_env);  // 设置 gc 线程退出
 
-    sleep(2);
-//    pthread_mutex_lock(&env->thread_lock);
-//    while (env->env_list != NULL)
-//        pthread_cond_wait(&env->thread_cond, &env->thread_lock);
-//    pthread_mutex_unlock(&env->thread_lock);
+    pthread_mutex_lock(&env->thread_lock);
+    while (env->env_list != NULL) {
+        pthread_mutex_unlock(&env->thread_lock);
+        safeSleep(0.1);
+        pthread_mutex_unlock(&env->thread_lock);
+    }
+    pthread_mutex_unlock(&env->thread_lock);
 }

+ 0 - 1
src/core/gc.c

@@ -128,7 +128,6 @@ void gc_delVarReference(af_Var *var, af_Environment *base) {
 
     pthread_mutex_lock(&base->gc_factory->mutex);
     var->gc.info.reference--;
-    writeTrackLog(aFunCoreLogger, "del VarSpace Reference");
     pthread_mutex_unlock(&base->gc_factory->mutex);
 }
 

+ 1 - 3
src/core/sig.c

@@ -9,9 +9,7 @@ struct af_SignalInfo {
     volatile sig_atomic_t flat_int;  // SIGUSR1 (*nix)
     volatile sig_atomic_t flat_term;  // SIGUSR1 (*nix)
 
-#ifdef aFunWIN32_NO_CYGWIN
-
-#else
+#ifndef aFunWIN32_NO_CYGWIN
     volatile sig_atomic_t flat_u1;  // SIGUSR1 (*nix)
     volatile sig_atomic_t flat_u2;  // SIGUSR1 (*nix)
 

+ 4 - 2
src/core/thread.c

@@ -63,10 +63,12 @@ static void *runThread(void *ec) {
     writeInfoLog(aFunCoreLogger, "Thread start");
     iterCode(code, 0, env);
 
-    writeInfoLog(aFunCoreLogger, "Thread free");
-    freeEnvironment(env);
+    writeInfoLog(aFunCoreLogger, "Thread free-code");
     freeAllCode(code);
 
+    writeInfoLog(aFunCoreLogger, "Thread free-env");
+    freeEnvironment(env);
+
     writeInfoLog(aFunCoreLogger, "Thread end");
     return NULL;
 }

+ 2 - 2
src/tool/file.c

@@ -10,6 +10,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "tool.h"
+
 #ifdef aFunWIN32_NO_CYGWIN
 #ifdef _MSC_VER
 #pragma warning(disable : 5105)  // 关闭 5105 的警告输出 (Windows.h中使用)
@@ -19,8 +21,6 @@
 #include <unistd.h>
 #endif
 
-#include "tool.h"
-
 #ifndef S_ISREG
 #define	S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
 #endif

+ 26 - 52
test/src/run_code.c

@@ -892,11 +892,9 @@ INIT_ERROR:
         printf("global(%p)\n", obj);
         gc_delReference(obj, env);
     }
-    printf("\n");
-    sleep(2);
 
     {  // 正常程序
-        printf("TAG A: [Normal test]\n");
+        printf("\nTAG A: [Normal test]\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Taga.aun");
         af_Code *bt2 = makeElementCode("data", 0, 0, NULL);
         pushCode(&bt1, bt2);
@@ -910,13 +908,10 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
-    sleep(2);
-
     {  // 宏函数
-        printf("TAG L: [Macro test]\n");
+        printf("\nTAG L: [Macro test]\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Tagl.aun");
 
         af_Code *bt3 = makeElementCode("macro", 0, 1, NULL);
@@ -928,11 +923,10 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 测试顺序执行 '(xxx)
-        printf("TAG E: [ex]\n");
+        printf("\nTAG E: [ex]\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
@@ -942,11 +936,10 @@ INIT_ERROR:
 
         runCodeFromMemory(bt5, 0, env);
         freeAllCode(bt5);
-        printf("\n");
     }
 
     {  // 尾调用优化
-        printf("TAG B: [Tail test]\n");
+        printf("\nTAG B: [Tail test]\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, NULL);
 
         af_Code *bt2 = makeElementCode("func-normal", 0, 1, NULL);
@@ -957,33 +950,30 @@ INIT_ERROR:
 
         runCodeFromMemory(bt4, 0, env);
         freeAllCode(bt4);
-        printf("\n");
     }
 
     {  // 尾调用优化2
-        printf("TAG C: [Tail test on literal]\n");
+        printf("\nTAG C: [Tail test on literal]\n");
         af_Code *bt1 = makeElementCode("data", 0, 0, "Tagc.aun");
         af_Code *bt2 = makeBlockCode(parentheses, bt1, '\'', 1, "Tagc.aun", NULL);
 
         runCodeFromMemory(bt2, 0, env);
         freeAllCode(bt2);
-        printf("\n");
     }
 
     {  // 测试类前缀调用
-        printf("TAG D: [parentheses-call]\n");
+        printf("\nTAG D: [parentheses-call]\n");
         af_Code *bt1 = makeElementCode("func-normal", 0, 1, "Tagd.aun");
         af_Code *bt2 = makeBlockCode(parentheses, NULL, 0, 1, NULL, NULL);
         pushCode(&bt1, bt2);
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
 
     {  // 测试顺序执行 $[xxx]
-        printf("TAG F: [ex-first]\n");
+        printf("\nTAG F: [ex-first]\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
@@ -993,52 +983,47 @@ INIT_ERROR:
 
         runCodeFromMemory(bt5, 0, env);
         freeAllCode(bt5);
-        printf("\n");
     }
 
 
     {  // 双层尾调用优化 (函数内调用函数)
-        printf("TAG I: [Double tail test]\n");
+        printf("\nTAG I: [Double tail test]\n");
         af_Code *bt1 = makeElementCode("func-tail", 0, 1, NULL);
         af_Code *bt2 = makeBlockCode(curly, bt1, 0, 1, "Tagi.aun", NULL);
         af_Code *bt3 = makeBlockCode(parentheses, bt2, '\'', 1, "Tagi.aun", NULL);
 
         runCodeFromMemory(bt3, 0, env);
         freeAllCode(bt3);
-        printf("\n");
     }
 
     {  // 对象函数的调用
-        printf("TAG J: [object]\n");
+        printf("\nTAG J: [object]\n");
         af_Code *bt1 = makeElementCode("func-obj", 0, 1, "Tagj.aun");
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 变量引用调用
-        printf("TAG K: [not object]\n");
+        printf("\nTAG K: [not object]\n");
         af_Code *bt1 = makeElementCode("func-obj", '\'', 1, "Tagk.aun");
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 对象函数的调用 (尾调用优化)
-        printf("TAG L: [pbject-tail]\n");
+        printf("\nTAG L: [pbject-tail]\n");
         af_Code *bt1 = makeElementCode("func-obj", 0, 1, "Tagl.aun");
         af_Code *bt2 = makeBlockCode(parentheses, bt1, '\'', 1, "Tagi.aun", NULL);
 
         runCodeFromMemory(bt2, 0, env);
         freeAllCode(bt2);
-        printf("\n");
     }
 
 
     {  // gc测试
-        printf("TAG N: [gc-test]\n");
+        printf("\nTAG N: [gc-test]\n");
 
         af_Code *bt2 = makeElementCode("func-gc", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagn.aun", NULL);
@@ -1050,33 +1035,30 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // func_body_dynamic 测试
-        printf("TAG O: [func body dynamic]\n");
+        printf("\nTAG O: [func body dynamic]\n");
 
         af_Code *bt2 = makeElementCode("func-body-dynamic", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tago.aun", NULL);
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 中缀调用测试
-        printf("TAG P: [infix-call]\n");
+        printf("\nTAG P: [infix-call]\n");
 
         af_Code *bt2 = makeElementCode("func-brackets", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Tagp.aun", NULL);
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // func_body_import 测试
-        printf("TAG Q: [import]\n");
+        printf("\nTAG Q: [import]\n");
 
         af_Code *bt2 = makeElementCode("func-import", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagq.aun", NULL);
@@ -1086,11 +1068,10 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 导入式运行
-        printf("TAG R: [import-Tagr]\n");
+        printf("\nTAG R: [import-Tagr]\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Tagr.aun");
         af_Code *bt2 = makeElementCode("data", 0, 0, NULL);
         pushCode(&bt1, bt2);
@@ -1104,13 +1085,12 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 1, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {
-        printf("TAG S: [string]\n");
+        printf("\nTAG S: [string]\n");
         int exit_code = runCodeFromString("str\ndata\n{func-normal}\nglobal\n", "Tags-string.aun", 1, env);
-        printf("exit code = %d\n\n", exit_code);
+        printf("exit code = %d\n", exit_code);
     }
 
     {
@@ -1123,7 +1103,7 @@ INIT_ERROR:
         FREE_SYMBOL(func);
         FREE_SYMBOL(des);
 
-        printf("TAG U: [guardian]\n");
+        printf("\nTAG U: [guardian]\n");
         af_Code *bt1 = makeElementCode("func-normal", 0, 1, "TagU.aun");
         af_Code *bt2 = makeElementCode("global", 0, 1, "TagU.aun");
         af_Code *bt3 = makeElementCode("global", 0, 1, "TagU.aun");
@@ -1138,48 +1118,44 @@ INIT_ERROR:
     }
 
     {
-        printf("TAG V: [Thread]\n");
+        printf("\nTAG V: [Thread]\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Tagv.aun");
 
         startRunThread(env, NULL, bt1, false, true, true, true, true);
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     // 错误用例
 
     {  // 中缀调用测试
-        printf("TAG a: ERROR\n");
+        printf("\nTAG a: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func-normal", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Taga-error.aun", NULL);
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 测试错误 (无函数指定)
-        printf("TAG b: ERROR\n");
+        printf("\nTAG b: ERROR\n");
         af_Code *bt1 = makeBlockCode(curly, NULL, 0, 1, "Tagb-error.aun", NULL);
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 测试错误 (object2 Var not found)
-        printf("TAG c: ERROR\n");
+        printf("\nTAG c: ERROR\n");
         af_Code *bt1 = makeElementCode("object2", 0, 1, "Tagc-error.aun");
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 中缀保护测试
-        printf("TAG d: ERROR\n");
+        printf("\nTAG d: ERROR\n");
 
         af_Code *bt1 = makeElementCode("global", 0, 1, "Tagd-error.aun");
         af_Code *bt2 = makeElementCode("func-brackets", 0, 2, NULL);
@@ -1188,11 +1164,10 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
     {  // 错误回溯测试
-        printf("TAG e: ERROR\n");
+        printf("\nTAG e: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func-no-var", 0, 1, NULL);
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tage-error.aun", NULL);
@@ -1202,10 +1177,9 @@ INIT_ERROR:
 
         runCodeFromMemory(bt1, 0, env);
         freeAllCode(bt1);
-        printf("\n");
     }
 
-    printf("freeEnvironment:\n");
+    printf("\nfreeEnvironment:\n");
     destructAFunEnvironment(env);
 
     undefRunEnv(&ri);