Fixed major bug with compiling in release-mode: wrong allocated memory. initTOS now takes size of TOS as parameter. Improved work with contexts: now memory releases after popping context from stack

This commit is contained in:
Alex Vanin 2014-01-29 21:37:48 +04:00
parent ff0ef7f0bb
commit e2d0d56299
5 changed files with 15 additions and 11 deletions

View file

@ -27,9 +27,12 @@ void push_context(context* cont)
}
context* pop_context()
{
context* poped = node_last->obj;
c_node* last = node_last;
node_last = node_last->prev;
return last->obj;
free(last);
return poped;
}
//Find Context in Context Stack.

View file

@ -58,7 +58,7 @@ int read_constant(FILE* stream, int* count, char*** index)
buffer = (char*)malloc(Const_Header.size_const+1);
buffer[0]=0;
*(index) = (char**)malloc(sizeof(char**)*Const_Header.count_const);
*(index) = (char**)malloc(sizeof(char**)*Const_Header.count_const+1);
fread_s(buffer+1, Const_Header.size_const, sizeof(char), Const_Header.size_const, stream); //Reading constant values

View file

@ -11,7 +11,7 @@
long long cmp_int(long long* a, long long* b);
double cmp_double(double* a, double* b);
void run_intepreter(char* filename);
int run_interpreter(char* filename);
int main(int argc, char** argv)
{
@ -21,8 +21,9 @@ int main(int argc, char** argv)
printf("%s", "File is not specified");
return 1;
}
return_code = run_interpreter(argv[1]);
return_code = run_interpreter(argv[1]);
return return_code;
}
int run_interpreter(char* filename)
@ -56,12 +57,13 @@ int run_interpreter(char* filename)
startfunc = read_bytecode(input, &phash_table);
fclose(input);
initTOS(3000);
initTOS();
initRStack(1000);
ip = 0;
current_context = create_context(startfunc, phash_table, &code);
node_last = NULL;
while (exec_status)
@ -603,7 +605,6 @@ int run_interpreter(char* filename)
}
}
remove_context(current_context);
getchar();
return 0;
}

View file

@ -33,9 +33,9 @@ double pop_double()
return num;
}
int initTOS()
int initTOS(int count)
{
TOS = (double*)calloc(1, 12000);
TOS = (double*)calloc(count, sizeof(double*));
tp = 0;
return 0;
}

View file

@ -9,7 +9,7 @@ typedef union
double* TOS;
int tp;
int initTOS();
int initTOS(int);
void push_int(long long);
void push_double(double);
long long pop_int();