Fixed Memory Leaks. :)

This commit is contained in:
Felix Brendel
2019-11-10 00:50:09 +01:00
parent a790a38655
commit bb1cfcd3c3
19 changed files with 199 additions and 173 deletions
+17 -14
View File
@@ -31,7 +31,7 @@ namespace Parser {
}
proc inject_scl(Lisp_Object* lo) -> void {
lo->sourceCodeLocation = new(Source_Code_Location);
lo->sourceCodeLocation = (Source_Code_Location*)malloc(sizeof(Source_Code_Location));
lo->sourceCodeLocation->file = parser_file;
lo->sourceCodeLocation->line = parser_line;
lo->sourceCodeLocation->column = parser_col;
@@ -65,7 +65,6 @@ namespace Parser {
++parser_col;
++(*index_in_text);
}
}
proc eat_until_code(char* text, int* index_in_text) -> void {
@@ -120,7 +119,7 @@ namespace Parser {
Lisp_Object* ret;
try ret = Memory::create_lisp_object_number(number);
inject_scl(ret);
// inject_scl(ret);
return ret;
}
@@ -132,7 +131,7 @@ namespace Parser {
Lisp_Object* ret;
try ret = Memory::get_or_create_lisp_object_keyword(str_keyword);
inject_scl(ret);
// inject_scl(ret);
return ret;
}
@@ -142,7 +141,7 @@ namespace Parser {
Lisp_Object* ret;
try ret = Memory::get_or_create_lisp_object_symbol(str_symbol);
inject_scl(ret);
// inject_scl(ret);
return ret;
}
@@ -157,7 +156,7 @@ namespace Parser {
Lisp_Object* ret;
try ret = Memory::create_lisp_object_string(
Memory::create_string("", 0));
inject_scl(ret);
// inject_scl(ret);
// plus one because we want to go after the quotes
*index_in_text += 1;
@@ -169,10 +168,10 @@ namespace Parser {
// okay so the first letter was not actually closing the string...
int string_length = 0;
bool escaping = false;
while (!(text[*index_in_text+string_length] == '"' && !escaping))
{
if (escaping)
while (escaping || text[*index_in_text+string_length] != '"') {
if (escaping) {
escaping = false;
}
else
if (text[*index_in_text+string_length] == '\\')
escaping = true;
@@ -186,9 +185,10 @@ namespace Parser {
// NOTE(Felix): Tactic: Through unescaping the string will
// only get shorter, so we replace it inplace and later jump
// to the original end of the string.
try unescape_string(text+(*index_in_text));
int new_len;
try new_len = unescape_string(text+(*index_in_text));
String* string = Memory::create_string("", string_length);
String* string = Memory::create_string("", new_len);
// TODO(Felix): manually copy to parse control sequences
// correctly without the need to unescape the string, also
@@ -196,6 +196,7 @@ namespace Parser {
// characters since last new line so we can update the parser
// location more easily
strcpy(&string->data, text+(*index_in_text));
// printf("------ %s\n", &string->data);
text[*index_in_text+string_length] = '"';
@@ -218,7 +219,7 @@ namespace Parser {
Lisp_Object* ret;
try ret = Memory::create_lisp_object_string(string);
inject_scl(ret);
// inject_scl(ret);
return ret;
}
@@ -285,7 +286,8 @@ namespace Parser {
try ret = Memory::create_list(Memory::get_or_create_lisp_object_symbol("unquote-splicing"), result);
}
if (ret) inject_scl(ret);
// if (ret && ret != Memory::nil && ret != Memory::t)
// inject_scl(ret);
return ret;
}
@@ -313,7 +315,7 @@ namespace Parser {
Lisp_Object* expression = head;
while (true) {
inject_scl(head);
// inject_scl(head);
if (text[*index_in_text] == '(' ||
text[*index_in_text] == '\''||
text[*index_in_text] == '`' ||
@@ -363,6 +365,7 @@ namespace Parser {
} else {
try head->value.pair.rest = Memory::create_lisp_object_pair(Memory::nil, Memory::nil);
head = head->value.pair.rest;
// inject_scl(head);
}
}
return expression;