diff --git a/src/c/module.d b/src/c/module.d index 84a588ba1..5e8101a27 100644 --- a/src/c/module.d +++ b/src/c/module.d @@ -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; } diff --git a/src/c/process.d b/src/c/process.d index f264a7afc..7260ed692 100644 --- a/src/c/process.d +++ b/src/c/process.d @@ -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; } diff --git a/src/c/stacks.d b/src/c/stacks.d index 12b98b070..9d4c8a16d 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -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; ivector.self.t[i] = ECL_NIL; +} + cl_object ecl_stack_push(cl_object self, cl_object elt) { diff --git a/src/h/external.h b/src/h/external.h index b995d84a7..56c2a2d8a 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -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);