fixed memory leaks introduced by continuations
This commit is contained in:
@@ -18,13 +18,13 @@ time clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS \
|
|||||||
src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 \
|
src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 \
|
||||||
-I3rd/ || exit 1
|
-I3rd/ || exit 1
|
||||||
|
|
||||||
# echo ""
|
echo ""
|
||||||
# echo "--------------------------------"
|
echo "--------------------------------"
|
||||||
# echo " compiling fullslime (release) "
|
echo " compiling fullslime (release) "
|
||||||
# echo "--------------------------------"
|
echo "--------------------------------"
|
||||||
# time clang++ -D_DONT_BREAK_ON_ERRORS -O3 \
|
time clang++ -D_DONT_BREAK_ON_ERRORS -O3 \
|
||||||
# src/main.cpp -g -o ./bin/slime --std=c++17 \
|
src/main.cpp -g -o ./bin/slime --std=c++17 \
|
||||||
# -I3rd/ || exit 1
|
-I3rd/ || exit 1
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "------------------------------"
|
echo "------------------------------"
|
||||||
|
|||||||
+3
-1
@@ -1319,7 +1319,9 @@ namespace Slime {
|
|||||||
// example, numbers are not valid symbols.
|
// example, numbers are not valid symbols.
|
||||||
|
|
||||||
try assert_type(str, Lisp_Object_Type::String);
|
try assert_type(str, Lisp_Object_Type::String);
|
||||||
return Memory::get_symbol(Memory::duplicate_string(str->value.string));
|
// TODO(Felix): It was like this: why did we have to copy it?
|
||||||
|
// return Memory::get_symbol(Memory::duplicate_string(str->value.string));
|
||||||
|
return Memory::get_symbol(str->value.string);
|
||||||
};
|
};
|
||||||
define((concat-strings . strings), "TODO") {
|
define((concat-strings . strings), "TODO") {
|
||||||
profile_with_name("(concat-strings)");
|
profile_with_name("(concat-strings)");
|
||||||
|
|||||||
@@ -445,6 +445,9 @@ namespace Slime {
|
|||||||
Globals::Current_Execution.cs.clear();
|
Globals::Current_Execution.cs.clear();
|
||||||
Globals::Current_Execution.ams.clear();
|
Globals::Current_Execution.ams.clear();
|
||||||
Globals::Current_Execution.pcs.clear();
|
Globals::Current_Execution.pcs.clear();
|
||||||
|
for (auto it: Globals::Current_Execution.nass) {
|
||||||
|
it.dealloc();
|
||||||
|
}
|
||||||
Globals::Current_Execution.nass.clear();
|
Globals::Current_Execution.nass.clear();
|
||||||
Globals::Current_Execution.envi_stack.clear();
|
Globals::Current_Execution.envi_stack.clear();
|
||||||
Globals::Current_Execution.ats.clear();
|
Globals::Current_Execution.ats.clear();
|
||||||
|
|||||||
+48
-20
@@ -100,6 +100,20 @@ namespace Slime::Memory {
|
|||||||
proc free_everything() -> void {
|
proc free_everything() -> void {
|
||||||
object_memory.for_each([](Lisp_Object* lo){
|
object_memory.for_each([](Lisp_Object* lo){
|
||||||
switch (lo->type) {
|
switch (lo->type) {
|
||||||
|
case Lisp_Object_Type::Continuation: {
|
||||||
|
lo->value.continuation->cs.dealloc();
|
||||||
|
lo->value.continuation->pcs.dealloc();
|
||||||
|
lo->value.continuation->ams.dealloc();
|
||||||
|
lo->value.continuation->ats.dealloc();
|
||||||
|
lo->value.continuation->mes.dealloc();
|
||||||
|
lo->value.continuation->envi_stack.dealloc();
|
||||||
|
for (auto it : lo->value.continuation->nass) {
|
||||||
|
it.dealloc();
|
||||||
|
}
|
||||||
|
lo->value.continuation->nass.dealloc();
|
||||||
|
free(lo->value.continuation);
|
||||||
|
|
||||||
|
} break;
|
||||||
case Lisp_Object_Type::Function: {
|
case Lisp_Object_Type::Function: {
|
||||||
lo->value.function->args.positional.symbols.dealloc();
|
lo->value.function->args.positional.symbols.dealloc();
|
||||||
lo->value.function->args.keyword.keywords.dealloc();
|
lo->value.function->args.keyword.keywords.dealloc();
|
||||||
@@ -140,6 +154,9 @@ namespace Slime::Memory {
|
|||||||
Globals::Current_Execution.ams.dealloc();
|
Globals::Current_Execution.ams.dealloc();
|
||||||
Globals::Current_Execution.pcs.dealloc();
|
Globals::Current_Execution.pcs.dealloc();
|
||||||
Globals::Current_Execution.nass.dealloc();
|
Globals::Current_Execution.nass.dealloc();
|
||||||
|
for (auto it: Globals::Current_Execution.nass) {
|
||||||
|
it.dealloc();
|
||||||
|
}
|
||||||
Globals::Current_Execution.ats.dealloc();
|
Globals::Current_Execution.ats.dealloc();
|
||||||
Globals::Current_Execution.mes.dealloc();
|
Globals::Current_Execution.mes.dealloc();
|
||||||
|
|
||||||
@@ -278,24 +295,28 @@ namespace Slime::Memory {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline proc full_clone_continuation(Continuation* c) -> Continuation* {
|
||||||
|
Continuation* res = (Continuation*)malloc(sizeof(Continuation));
|
||||||
|
res->cs = c->cs.clone();
|
||||||
|
res->pcs = c->pcs.clone();
|
||||||
|
res->ams = c->ams.clone();
|
||||||
|
res->ats = c->ats.clone();
|
||||||
|
res->mes = c->mes.clone();
|
||||||
|
res->envi_stack = c->envi_stack.clone();
|
||||||
|
res->nass = c->nass.clone();
|
||||||
|
|
||||||
|
for (u32 i = 0; i < res->nass.next_index; ++i) {
|
||||||
|
res->nass.data[i] = c->nass.data[i].clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
proc create_lisp_object_continuation() -> Lisp_Object* {
|
proc create_lisp_object_continuation() -> Lisp_Object* {
|
||||||
using Globals::Current_Execution;
|
|
||||||
Lisp_Object* node;
|
Lisp_Object* node;
|
||||||
try node = create_lisp_object();
|
try node = create_lisp_object();
|
||||||
node->type = Lisp_Object_Type::Continuation;
|
node->type = Lisp_Object_Type::Continuation;
|
||||||
node->value.continuation = (Continuation*)malloc(sizeof(Continuation));
|
node->value.continuation = full_clone_continuation(&Globals::Current_Execution);
|
||||||
node->value.continuation->cs = Current_Execution.cs.clone();
|
|
||||||
node->value.continuation->pcs = Current_Execution.pcs.clone();
|
|
||||||
node->value.continuation->ams = Current_Execution.ams.clone();
|
|
||||||
node->value.continuation->ats = Current_Execution.ats.clone();
|
|
||||||
node->value.continuation->mes = Current_Execution.mes.clone();
|
|
||||||
node->value.continuation->envi_stack = Current_Execution.envi_stack.clone();
|
|
||||||
|
|
||||||
node->value.continuation->nass = Current_Execution.nass.clone();
|
|
||||||
for (u32 i = 0; i < node->value.continuation->nass.next_index; ++i) {
|
|
||||||
node->value.continuation->nass.data[i] = node->value.continuation->nass.data[i].clone();
|
|
||||||
}
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,19 +475,25 @@ namespace Slime::Memory {
|
|||||||
if (n == Memory::nil || n == Memory::t) {
|
if (n == Memory::nil || n == Memory::t) {
|
||||||
return n;
|
return n;
|
||||||
} else {
|
} else {
|
||||||
Lisp_Object_Type type = n->type;
|
switch(n->type) {
|
||||||
if (type == Lisp_Object_Type::Symbol ||
|
case Lisp_Object_Type::Symbol:
|
||||||
type == Lisp_Object_Type::Keyword ||
|
case Lisp_Object_Type::Keyword:
|
||||||
type == Lisp_Object_Type::Function)
|
case Lisp_Object_Type::Function:
|
||||||
{
|
|
||||||
return n;
|
return n;
|
||||||
} else if (type == Lisp_Object_Type::String) {
|
case Lisp_Object_Type::String: {
|
||||||
Lisp_Object* target;
|
Lisp_Object* target;
|
||||||
try target = create_lisp_object();
|
try target = create_lisp_object();
|
||||||
*target = *n;
|
*target = *n;
|
||||||
target->value.string = create_string(target->value.string.data);
|
target->value.string = create_string(target->value.string.data);
|
||||||
return target;
|
return target;
|
||||||
} else {
|
}
|
||||||
|
case Lisp_Object_Type::Continuation:
|
||||||
|
Lisp_Object* target;
|
||||||
|
try target = create_lisp_object();
|
||||||
|
*target = *n;
|
||||||
|
target->value.continuation = full_clone_continuation(n->value.continuation);
|
||||||
|
return target;
|
||||||
|
default: {
|
||||||
Lisp_Object* target;
|
Lisp_Object* target;
|
||||||
try target = create_lisp_object();
|
try target = create_lisp_object();
|
||||||
*target = *n;
|
*target = *n;
|
||||||
@@ -475,6 +502,7 @@ namespace Slime::Memory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proc copy_lisp_object_except_pairs(Lisp_Object* n) -> Lisp_Object* {
|
proc copy_lisp_object_except_pairs(Lisp_Object* n) -> Lisp_Object* {
|
||||||
if (n->type == Lisp_Object_Type::Pair)
|
if (n->type == Lisp_Object_Type::Pair)
|
||||||
|
|||||||
Reference in New Issue
Block a user