From 023d147e142d7156f2d213051025ad8aa71b04a7 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 23 Oct 2020 16:55:11 +0000 Subject: [PATCH] cleanup of gchdr'ed objects in moo_fini() --- moo/lib/exec.c | 7 +++++-- moo/lib/moo.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 349879f..497284d 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -205,6 +205,9 @@ static MOO_INLINE void vm_cleanup (moo_t* moo) */ moo_deregallfinalizables (moo); + /* final garbage collection */ + moo_gc (moo); + MOO_DEBUG0 (moo, "VM cleaned up\n"); } @@ -688,8 +691,7 @@ static void terminate_process (moo_t* moo, moo_oop_process_t proc) proc->sp = MOO_SMOOI_TO_OOP(-1); /* invalidate the process stack */ MOO_STORE_OOP (moo, (moo_oop_t*)&proc->current_context, (moo_oop_t)proc->initial_context); /* not needed but just in case */ - /* a runnable or running process must not be chanined to the - * process list of a semaphore */ + /* a runnable or running process must not be chanined to the process list of a semaphore */ MOO_ASSERT (moo, (moo_oop_t)proc->sem == moo->_nil); if (nrp == proc) @@ -5146,6 +5148,7 @@ static MOO_INLINE int switch_process_if_needed (moo_t* moo) "%zd suspended process(es) found - check your program\n", MOO_OOP_TO_SMOOI(moo->processor->suspended.count)); } + return 0; } diff --git a/moo/lib/moo.c b/moo/lib/moo.c index 4bd8a2a..eb8f5bd 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -250,8 +250,24 @@ void moo_fini (moo_t* moo) * the heap may not exist */ if (moo->heap) moo_killheap (moo, moo->heap); +#if defined(MOO_ENABLE_GC_MARK_SWEEP) + if (moo->gch) + { + moo_gchdr_t* next; + + do + { + next = moo->gch->next; + moo_freemem (moo, moo->gch); + moo->gch = next; + } + while (moo->gch); + } +#endif + moo_finidbgi (moo); + for (i = 0; i < MOO_COUNTOF(moo->sbuf); i++) { if (moo->sbuf[i].ptr)