Parcourir la source

fix: 修复了725e4ab9b引入的gc问题

在725e4ab9b中因为没有释放result导致了gc问题
现在已经修复

link #6
SongZihuan il y a 4 ans
Parent
commit
ec8046e397

+ 17 - 1
VirtulMathCore/ofunc/src/dictiter.c

@@ -16,10 +16,14 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
         return R_error;
     }
     {
-        LinkValue *keys = findAttributes(L"keys", false, 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[1].value));
+        LinkValue *keys = NULL;
         Argument *list_arg = NULL;
         LinkValue *listiter_class = NULL;
 
+        freeResult(result);
+        keys = findAttributes(L"keys", false, 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[1].value));
+        if (!CHECK_RESULT(result))
+            return result->type;
         if (keys == NULL){
             setResultError(E_TypeException, L"Object non-key-value pairs (there is no keys method)", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return R_error;
@@ -75,18 +79,26 @@ ResultType dictiter_next(OFFICAL_FUNCTIONSIG){
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return result->type;
+    freeResult(result);
+
     list_ = findAttributes(L"__list", false, 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
     if (list_ == NULL){
         setResultError(E_TypeException, VALUE_ERROR(__list, listiter), 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
 
+    freeResult(result);
     list_next = findAttributes(inter->data.object_next, false, 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, list_));
+    if (!CHECK_RESULT(result))
+        return result->type;
     if (list_next == NULL){
         setResultError(E_TypeException, L"Object is not iterable", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
 
+    freeResult(result);
     callBackCore(list_next, NULL, 0, "sys", 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
@@ -100,7 +112,11 @@ ResultType dictiter_down(OFFICAL_FUNCTIONSIG){
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return result->type;
+    freeResult(result);
+
     dict_ = findAttributes(L"__dict", false, 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
     if (dict_ == NULL || dict_->value->type != V_dict){
         setResultError(E_TypeException, VALUE_ERROR(__dict, dict), 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;

+ 2 - 0
VirtulMathCore/ofunc/src/list.c

@@ -362,6 +362,8 @@ ResultType listRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
     }
     lt = value->data.list.type;
     again = findAttributes(is_repo ? L"repo_again" : L"str_again", false, 0, "list.repo", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
     if (again != NULL){
         bool again_ = checkBool(again, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!CHECK_RESULT(result))

+ 16 - 0
VirtulMathCore/ofunc/src/listiter.c

@@ -38,8 +38,24 @@ ResultType listiter_next(OFFICAL_FUNCTIONSIG){
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return result->type;
+    freeResult(result);
+
     list_ = findAttributes(L"__list", false, 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
+    if (list_ == NULL){
+        setResultError(E_TypeException, VALUE_ERROR(__list, listiter), 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return R_error;
+    }
+
+    freeResult(result);
     index = findAttributes(L"__index", false, 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
+    if (index == NULL){
+        setResultError(E_TypeException, VALUE_ERROR(__index, listiter), 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return R_error;
+    }
 
     if (list_->value->type != V_list){
         setResultError(E_TypeException, VALUE_ERROR(listiter.__list, list), 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));

+ 4 - 0
VirtulMathCore/ofunc/src/object.c

@@ -31,6 +31,10 @@ ResultType objectRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
     freeResult(result);
 
     name_value = findAttributes(inter->data.object_name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
+    freeResult(result);
+
     if (name_value != NULL){
         gc_addTmpLink(&name_value->gc_status);
         name = getRepoStr(name_value, is_repo, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));

+ 6 - 1
VirtulMathCore/ofunc/src/str.c

@@ -5,12 +5,14 @@ ResultType str_new(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.must=-1}};
     int status = 1;
+    setResultCore(result);
     arg = parserValueArgument(ap, arg, &status, NULL);
     if (status != 1){
         setResultError(E_ArgumentException, FEW_ARG, 0, "str.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
-    setResultCore(result);
+    freeResult(result);
+
     value = make_new(inter, belong, ap[0].value);
     value->value->type = V_str;
     value->value->data.str.str = memWidecpy(L"");
@@ -160,7 +162,10 @@ ResultType str_iter(OFFICAL_FUNCTIONSIG){
     if (!CHECK_RESULT(result))
         return result->type;
     freeResult(result);
+
     to_list = findAttributes(L"to_list", false, 0, "str", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
+    if (!CHECK_RESULT(result))
+        return result->type;
     if (to_list == NULL){
         setResultError(E_TypeException, L"String cannot be converted to list", 0, "str", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;

+ 44 - 11
VirtulMathCore/src/__run.c

@@ -327,7 +327,7 @@ void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fli
 LinkValue *findAttributes(wchar_t *name, bool free_old, fline line, char *file, bool nowrun, INTER_FUNCTIONSIG_NOT_ST) {  // TODO-szh 处理调用该函数的地方释放result
     LinkValue *attr;
     gc_freeze(inter, var_list, belong->value->object.var, true);
-    attr = findStrVar(name, free_old, line, file, nowrun, CALL_INTER_FUNCTIONSIG_NOT_ST(belong->value->object.var, result, belong));
+    attr = findStrVar(name, free_old, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(belong->value->object.var, result, belong));  // TODO-szh 重新启动
     if (attr != NULL && (attr->belong == NULL || attr->belong->value != belong->value && checkAttribution(belong->value, attr->belong->value)))
         attr->belong = belong;
     gc_freeze(inter, var_list, belong->value->object.var, false);
@@ -358,6 +358,7 @@ bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, c
     gc_freeze(inter, var_list, belong->value->object.var, false);
 
     gc_freeTmpLink(&name_->gc_status);
+
     return_:
     memFree(var_name);
     return CHECK_RESULT(result);
@@ -366,11 +367,12 @@ bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, c
 void newObjectSetting(LinkValue *name, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     setResultCore(result);
     addAttributes(inter->data.object_name, false, name, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (CHECK_RESULT(result))
+    if (!CHECK_RESULT(result))
         return;
     freeResult(result);
+
     addAttributes(inter->data.object_self, false, belong, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (CHECK_RESULT(result) && belong->value->object.inherit != NULL) {
+    if (!CHECK_RESULT(result) && belong->value->object.inherit != NULL) {
         freeResult(result);
         addAttributes(inter->data.object_father, false, belong->value->object.inherit->value, line, file, false,
                       CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -385,6 +387,9 @@ ResultType getElement(LinkValue *from, LinkValue *index, fline line, char *file,
     gc_addTmpLink(&index->gc_status);
 
     _func_ = findAttributes(inter->data.object_down, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, from));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
     if (_func_ != NULL){
         Argument *arg = NULL;
         gc_addTmpLink(&_func_->gc_status);
@@ -396,6 +401,7 @@ ResultType getElement(LinkValue *from, LinkValue *index, fline line, char *file,
     else
         setResultError(E_TypeException, OBJ_NOTSUPPORT(subscript(__down__)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
+    return_:
     gc_freeTmpLink(&from->gc_status);
     gc_freeTmpLink(&index->gc_status);
     return result->type;
@@ -404,11 +410,16 @@ ResultType getElement(LinkValue *from, LinkValue *index, fline line, char *file,
 ResultType getIter(LinkValue *value, int status, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *_func_ = NULL;
     setResultCore(result);
+    gc_addTmpLink(&value->gc_status);
+
     if (status == 1)
         _func_ = findAttributes(inter->data.object_iter, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
     else
         _func_ = findAttributes(inter->data.object_next, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
 
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
     if (_func_ != NULL){
         gc_addTmpLink(&_func_->gc_status);
         callBackCore(_func_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -417,11 +428,15 @@ ResultType getIter(LinkValue *value, int status, fline line, char *file, INTER_F
     else
         setResultError(E_TypeException, OBJ_NOTSUPPORT(iter), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
+    return_:
+    gc_freeTmpLink(&value->gc_status);
     return result->type;
 }
 
 bool checkBool(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){
     LinkValue *_bool_ = findAttributes(inter->data.object_bool, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+    if (!CHECK_RESULT(result))
+        return false;
     if (_bool_ != NULL){
         gc_addTmpLink(&_bool_->gc_status);
         callBackCore(_bool_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -438,25 +453,34 @@ bool checkBool(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_S
 }
 
 wchar_t *getRepoStr(LinkValue *value, bool is_repo, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){
-    LinkValue *_repo_ = findAttributes(is_repo ? inter->data.object_repo : inter->data.object_str, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+    LinkValue *_repo_;
+    wchar_t *re = NULL;
     setResultCore(result);
+    gc_addTmpLink(&value->gc_status);
+
+    _repo_ = findAttributes(is_repo ? inter->data.object_repo : inter->data.object_str, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_repo_ != NULL){
-        gc_addTmpLink(&value->gc_status);
         gc_addTmpLink(&_repo_->gc_status);
         callBackCore(_repo_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_repo_->gc_status);
-        gc_freeTmpLink(&value->gc_status);
         if (!CHECK_RESULT(result))
-            return NULL;
+            goto return_;
         else if (result->value->value->type != V_str){
             setResultError(E_TypeException, OBJ_NOTSUPPORT(repo(str)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-            return NULL;
+            goto return_;
         }
-        return result->value->value->data.str.str;
+        re = result->value->value->data.str.str;
     }
     else
         setResultError(E_TypeException, OBJ_NOTSUPPORT(repo(str)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    return NULL;
+
+    return_:
+    gc_freeTmpLink(&value->gc_status);
+    return re;
 }
 
 bool is_iterStop(LinkValue *value, Inter *inter) {
@@ -500,7 +524,13 @@ LinkValue *make_new(Inter *inter, LinkValue *belong, LinkValue *class){
 
 static int init_new(LinkValue *obj, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *_init_ = NULL;
+    setResultCore(result);
+
     _init_ = findAttributes(inter->data.object_init, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
+    if (!CHECK_RESULT(result))
+        return -1;
+    freeResult(result);
+
 
     if (_init_ == NULL) {
         if (arg != NULL) {
@@ -509,16 +539,19 @@ static int init_new(LinkValue *obj, Argument *arg, fline line, char *file, INTER
         } else
             return 1;
     }
-    _init_->belong = obj;
+
     gc_addTmpLink(&_init_->gc_status);
+    _init_->belong = obj;
     callBackCore(_init_, arg, 0, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
     gc_freeTmpLink(&_init_->gc_status);
+
     return CHECK_RESULT(result) ? 1 : -1;
 }
 
 int run_init(LinkValue *obj, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     int return_;
     setResultCore(result);
+
     return_ = init_new(obj, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (return_ == 1) {
         freeResult(result);

+ 3 - 0
VirtulMathCore/src/ofunc.c

@@ -28,6 +28,7 @@ void presetting(Inter *inter) {
 
     functionPresetting(func, &func_new, &func_init, inter);
     strFunctionPresetting(func, func_new, func_init, inter);
+
     functionPresettingLast(func, func_new, func_init, inter);
 }
 
@@ -35,6 +36,7 @@ void registeredFunctionName(Inter *inter, LinkValue *belong){
     makeBaseObject(inter, belong);
 
     makeBaseVObject(inter);
+
     makeBaseNum(inter);
     makeBaseBool(inter);
     makeBaseEllipisis(inter);
@@ -47,6 +49,7 @@ void registeredFunctionName(Inter *inter, LinkValue *belong){
 
     makeBaseStr(inter);
     presetting(inter);
+
     registeredObject(inter->base_belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     registeredBaseFunction(inter->base_belong, inter);
 }

+ 18 - 0
VirtulMathCore/src/runbranch.c

@@ -565,8 +565,18 @@ ResultType forBranch(INTER_FUNCTIONSIG) {
 }
 
 static bool getEnterExit(LinkValue *value, LinkValue **_enter_, LinkValue **_exit_, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+    setResultCore(result);
+
     *_enter_ = findAttributes(inter->data.object_enter, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+    if (!CHECK_RESULT(result))
+        return false;
+    freeResult(result);
+
     *_exit_ = findAttributes(inter->data.object_exit, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+    if (!CHECK_RESULT(result))
+        return false;
+    freeResult(result);
+
     if (*_enter_ == NULL || *_exit_ == NULL) {
         *_enter_ = NULL;
         *_exit_ = NULL;
@@ -600,9 +610,17 @@ static int runWithList(StatementList *with_list, LinkValue **with_belong, LinkVa
         gc_addTmpLink(&(*with_belong)->gc_status);
 
         *_enter_ = findAttributes(inter->data.object_enter, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, *value));
+        if (!CHECK_RESULT(result))
+            goto error_;
+        freeResult(result);
+
         *_exit_ = findAttributes(inter->data.object_exit, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, *value));
+        if (!CHECK_RESULT(result))
+            goto error_;
+        freeResult(result);
 
         if (!getEnterExit(*value, _enter_, _exit_, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+            error_:
             gc_freeTmpLink(&(*value)->gc_status);
             gc_freeTmpLink(&(*with_belong)->gc_status);
             *value = NULL;

+ 25 - 4
VirtulMathCore/src/runcall.c

@@ -123,6 +123,10 @@ ResultType elementSlice(INTER_FUNCTIONSIG) {
 
     func_name = st->u.slice_.type == SliceType_down_ ? inter->data.object_down : inter->data.object_slice;
     _func_ = findAttributes(func_name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, element));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_func_ != NULL){
         gc_addTmpLink(&_func_->gc_status);
         callBackCorePt(_func_, st->u.slice_.index, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -131,6 +135,7 @@ ResultType elementSlice(INTER_FUNCTIONSIG) {
     else
         setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(__down__/__slice__), true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
+    return_:
     gc_freeTmpLink(&element->gc_status);
     return result->type;
 }
@@ -175,23 +180,37 @@ ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, c
 }
 
 static ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
-    LinkValue *_new_ = findAttributes(inter->data.object_new, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, class_value));
+    LinkValue *_new_;
     setResultCore(result);
+    gc_addTmpLink(&class_value->gc_status);
+
+    _new_ = findAttributes(inter->data.object_new, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, class_value));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_new_ != NULL){
         gc_addTmpLink(&_new_->gc_status);
         callBackCore(_new_, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_new_->gc_status);
     }
     else
-        setResultError(E_TypeException, OBJ_NOTSUPPORT(new(__new__)), line, file, true,
-                       CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(new(__new__)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
+    return_:
+    gc_freeTmpLink(&class_value->gc_status);
     return result->type;
 }
 
 static ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
-    LinkValue *_call_ = findAttributes(inter->data.object_call, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, object_value));
+    LinkValue *_call_;
     setResultCore(result);
+    gc_addTmpLink(&object_value->gc_status);
+
+    _call_ = findAttributes(inter->data.object_call, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, object_value));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
 
     if (_call_ != NULL){
         gc_addTmpLink(&_call_->gc_status);
@@ -201,6 +220,8 @@ static ResultType callObject(LinkValue *object_value, Argument *arg, fline line,
     else
         setResultError(E_TypeException, OBJ_NOTSUPPORT(call(__call__)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
+    return_:
+    gc_freeTmpLink(&object_value->gc_status);
     return result->type;
 }
 

+ 21 - 3
VirtulMathCore/src/runoperation.c

@@ -223,10 +223,15 @@ ResultType downDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
     iter = result->value;
     result->value = NULL;
     freeResult(result);
+
     if (name->u.slice_.type == SliceType_down_)
         _func_ = findAttributes(inter->data.object_down_del, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
     else
         _func_ = findAttributes(inter->data.object_slice_del, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_func_ != NULL){
         Argument *arg = NULL;
         gc_addTmpLink(&_func_->gc_status);
@@ -243,6 +248,8 @@ ResultType downDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
     }
     else
         setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(del(__down_del__/__slice_del__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+
+    return_:
     gc_freeTmpLink(&iter->gc_status);
     return result->type;
 }
@@ -376,10 +383,15 @@ ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
     iter = result->value;
     result->value = NULL;
     freeResult(result);
+
     if (name->u.slice_.type == SliceType_down_)
         _func_ = findAttributes(inter->data.object_down_assignment, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
     else
         _func_ = findAttributes(inter->data.object_slice_assignment, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_func_ != NULL){
         Argument *arg = makeValueArgument(value);
         gc_addTmpLink(&_func_->gc_status);
@@ -396,6 +408,8 @@ ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
     }
     else
         setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(assignment(__down_assignment__/__slice_assignment__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+
+    return_:
     gc_freeTmpLink(&iter->gc_status);
     return result->type;
 }
@@ -578,15 +592,18 @@ ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name) {
     setResultCore(&left);
     setResultCore(&right);
 
-    if (getLeftRightValue(&left, &right, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
+    if (getLeftRightValue(&left, &right, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))  // 不需要释放result
         return result->type;
 
     _func_ = findAttributes(name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, left.value));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_func_ != NULL){
         Argument *arg = makeValueArgument(right.value);
         gc_addTmpLink(&_func_->gc_status);
-        callBackCore(_func_, arg, st->line, st->code_file, 0,
-                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_func_, arg, st->line, st->code_file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_func_->gc_status);
         freeArgument(arg, true);
     }
@@ -596,6 +613,7 @@ ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name) {
         memFree(message);
     }
 
+    return_:
     freeResult(&left);
     freeResult(&right);
     return result->type;

+ 20 - 6
VirtulMathCore/src/value.c

@@ -78,6 +78,7 @@ Value *makeStringValue(wchar_t *str, fline line, char *file, INTER_FUNCTIONSIG_N
     callBackCore(inter->data.str, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
+
     tmp = result->value->value;
     memFree(tmp->data.str.str);
     tmp->data.str.str = memWidecpy(str);
@@ -339,7 +340,15 @@ LinkValue *findBaseError(BaseErrorType type, Inter *inter){
 
 static wchar_t *getErrorInfo(LinkValue *exc, int type, INTER_FUNCTIONSIG_NOT_ST){
     wchar_t *str_name = type == 1 ? inter->data.object_name : inter->data.object_message;
-    LinkValue *_info_ = findAttributes(str_name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, exc));
+    LinkValue *_info_;
+    setResultCore(result);
+    gc_addTmpLink(&exc->gc_status);
+
+    _info_ = findAttributes(str_name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, exc));
+    gc_freeTmpLink(&exc->gc_status);
+    if (!CHECK_RESULT(result))
+        return NULL;
+
     if (_info_ != NULL && _info_->value->type == V_str)
         return memWidecpy(_info_->value->data.str.str);
     else
@@ -347,12 +356,17 @@ static wchar_t *getErrorInfo(LinkValue *exc, int type, INTER_FUNCTIONSIG_NOT_ST)
 }
 
 void callException(LinkValue *exc, wchar_t *message, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
-    LinkValue *_new_ = findAttributes(inter->data.object_new, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, exc));
+    LinkValue *_new_;
     wchar_t *type = NULL;
     wchar_t *error_message = NULL;
     setResultCore(result);
     gc_addTmpLink(&exc->gc_status);
 
+    _new_ = findAttributes(inter->data.object_new, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, exc));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    freeResult(result);
+
     if (_new_ != NULL){
         Argument *arg = NULL;
         LinkValue *error;
@@ -625,10 +639,10 @@ bool checkAttribution(Value *self, Value *father){
 void printValue(Value *value, FILE *debug, bool print_father, bool print_in) {
     switch (value->type){
         case V_num:
-            fprintf(debug, "%lld", value->data.num.num);
+            fprintf(debug, "(%lld)", value->data.num.num);
             break;
         case V_str:
-            fprintf(debug, "%ls", value->data.str.str);
+            fprintf(debug, "'%ls'", value->data.str.str);
             break;
         case V_func:
             if (print_father)
@@ -673,9 +687,9 @@ void printValue(Value *value, FILE *debug, bool print_father, bool print_in) {
             break;
         case V_class:
             if (print_father)
-                fprintf(debug, "V_class");
+                fprintf(debug, "class");
             else
-                fprintf(debug, "(V_class on %p)", value);
+                fprintf(debug, "(class on %p)", value);
             break;
         case V_obj:
             if (print_father)