Browse Source

fix: 修复了;实参赋值的内存错误

bug提交efba3bd84ec
内存错误的原因是double free
因为在调整形参链的时候释放了某些节点
现在不提前释放节点

link #6
SongZihuan 4 năm trước cách đây
mục cha
commit
0350025acc
4 tập tin đã thay đổi với 14 bổ sung39 xóa
  1. 9 16
      VirtulMathCore/src/__run.c
  2. 1 1
      VirtulMathCore/src/include/__run.h
  3. 4 4
      VirtulMathCore/src/runcall.c
  4. 0 18
      main.c

+ 9 - 16
VirtulMathCore/src/__run.c

@@ -134,7 +134,7 @@ void updateFunctionYield(Statement *function_st, Statement *node){
     function_st->info.have_info = true;
 }
 
-ResultType setFunctionArgument(Argument **arg, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST){
+ResultType setFunctionArgument(Argument **arg, Argument **base, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST){
     Argument *tmp = NULL;
     LinkValue *self;
     LinkValue *func;
@@ -145,16 +145,14 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *_func, fline line, cha
         case 0:
             func = _func;
             self = _func->belong;
+            *base = *arg;
             break;
         case 1: {
-            Argument *backup;
             func = _func;
             if (*arg != NULL) {
                 self = (*arg)->data.value;
-                backup = (*arg)->next;
-                (*arg)->next = NULL;
-                freeArgument(*arg, true);
-                *arg = backup;
+                *arg = (*arg)->next;
+                *base = *arg;
             } else {
                 error_:
                 setResultError(E_ArgumentException, FEW_ARG, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -163,17 +161,12 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *_func, fline line, cha
             break;
         }
         case 2: {
-            Argument *backup;
-            printf("TAG A\n");
             if (*arg != NULL && (*arg)->next != NULL) {
-                func = (*arg)->data.value;
-                self = (*arg)->next->data.value;
-
-                backup = (*arg)->next->next;
-                (*arg)->next->next = NULL;
-                freeArgument(*arg, true);
-                *arg = backup;
-                printf("TAG B\n");
+                self = (*arg)->data.value;
+                func = (*arg)->next->data.value;
+
+                *arg = (*arg)->next->next;
+                *base = *arg;
             } else
                 goto error_;
             break;

+ 1 - 1
VirtulMathCore/src/include/__run.h

@@ -20,7 +20,7 @@ void newWithBranchYield(Statement *branch_st, Statement *node, StatementList *sl
 void newForBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, VarList *new_var, enum StatementInfoStatus status,
                        Inter *inter, LinkValue *iter);
 
-ResultType setFunctionArgument(struct Argument **arg, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST);
+ResultType setFunctionArgument(struct Argument **arg, struct Argument **base, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST);
 void freeFunctionArgument(Argument *arg, Argument *base);
 LinkValue *findStrVar(char *name, bool free_old, INTER_FUNCTIONSIG_CORE);
 LinkValue *checkStrVar(char *name, bool free_old, INTER_FUNCTIONSIG_CORE);

+ 4 - 4
VirtulMathCore/src/runcall.c

@@ -207,11 +207,11 @@ static ResultType callObject(LinkValue *object_value, Argument *arg, fline line,
 static ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST){
     VarList *function_var = NULL;
     OfficialFunction of = NULL;
-    Argument *bak = arg;
+    Argument *bak;
     setResultCore(result);
     gc_addTmpLink(&function_value->gc_status);
 
-    setFunctionArgument(&arg, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setFunctionArgument(&arg, &bak, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
 
@@ -237,7 +237,7 @@ static ResultType callCFunction(LinkValue *function_value, Argument *arg, long i
 static ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
     VarList *var_func = NULL;
     Statement *st_func = NULL;
-    Argument *bak = arg;
+    Argument *bak;
     Parameter *pt_func = function_value->value->data.function.pt;
     bool yield_run = false;
     setResultCore(result);
@@ -254,7 +254,7 @@ static ResultType callVMFunction(LinkValue *function_value, Argument *arg, long
 
     gc_freeze(inter, var_list, var_func, true);
 
-    setFunctionArgument(&arg, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setFunctionArgument(&arg, &bak, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
     freeResult(result);

+ 0 - 18
main.c

@@ -21,21 +21,3 @@ int main(int argc, char *argv[]) {
     freeInter(inter, true);
     return 0;
 }
-
-/**
-class A{
-	def __init__(self, n) {
-		self.num = n
-	}
-
-	def printNum(self) {
-		print(self.num)
-	}
-}
-
-a = A(5)
-b = A(10)
-# a.printNum(20, b;)
-a.printNum(b, 20;)  // 运行到此处会内存错误
-
- */