modules: deallocate stacks when modules are destroyed

This commit is contained in:
Daniel Kochmański 2025-06-06 14:08:40 +02:00
parent f1ffa821ce
commit 7894622840
4 changed files with 21 additions and 0 deletions

View file

@ -183,4 +183,6 @@ free_modules(void)
loop_across_stack_filo(var, ecl_core.modules) {
ecl_del_module(var);
} end_loop_across_stack();
ecl_free_stack(ecl_core.modules);
ecl_core.modules = ECL_NIL;
}

View file

@ -260,7 +260,12 @@ free_cpu_process(cl_env_ptr the_env)
#ifdef ECL_WINDOWS_THREADS
CloseHandle(the_env->thread);
#endif
#if 0
/* KLUDGE when we destroy the module in destroy_process, the stack is freed
and threads are dereferenced. It might be that GC will try to pick them up
to run finalizers -- in that case we will still require a process env. */
ecl_set_process_env(NULL);
#endif
return ECL_NIL;
}
@ -276,6 +281,10 @@ free_env_process(cl_env_ptr the_env)
static cl_object
destroy_process(void)
{
#ifdef ECL_THREADS
ecl_free_stack(ecl_core.threads);
ecl_core.threads = ECL_NIL;
#endif
return ECL_NIL;
}

View file

@ -1061,6 +1061,14 @@ ecl_stack_index(cl_object self) {
return self->vector.fillp;
}
void
ecl_wipe_stack(cl_object self) {
int i, fp=self->vector.fillp;
self->vector.fillp = 0;
for (i=0; i<fp; i++)
self->vector.self.t[i] = ECL_NIL;
}
cl_object
ecl_stack_push(cl_object self, cl_object elt)
{

View file

@ -307,6 +307,8 @@ extern ECL_API cl_index ecl_atomic_index_incf(cl_index *slot);
/* stack.c */
extern ECL_API cl_object ecl_make_stack(cl_index dim);
extern ECL_API void ecl_free_stack(cl_object o);
extern ECL_API void ecl_wipe_stack(cl_object o);
extern ECL_API cl_object ecl_stack_push(cl_object stack, cl_object elt);
extern ECL_API cl_object ecl_stack_del(cl_object stack, cl_object elt);
extern ECL_API cl_object ecl_stack_popu(cl_object stack);