diff --git a/src/c/alloc_2.d b/src/c/alloc_2.d index 84edde4d4..f026bc56e 100644 --- a/src/c/alloc_2.d +++ b/src/c/alloc_2.d @@ -32,9 +32,10 @@ struct typemanager tm_table[(int)t_end]; static void finalize(cl_object o, cl_object data) { + CL_NEWENV_BEGIN { switch (type_of(o)) { #ifdef ENABLE_DLOPEN - case t_codeblock: + case t_codeblock: { cl_mapc(2, @'si::unlink-symbol', o->cblock.links); if (o->cblock.handle != NULL) { printf("\n;;; Freeing library %s\n", o->cblock.name? @@ -46,13 +47,14 @@ finalize(cl_object o, cl_object data) #endif break; #endif + } case t_stream: if (o->stream.file != NULL) fclose(o->stream.file); o->stream.file = NULL; break; - default: - } + default:} + } CL_NEWENV_END; } cl_object diff --git a/src/c/gbc.d b/src/c/gbc.d index 42fb3495b..d83368742 100644 --- a/src/c/gbc.d +++ b/src/c/gbc.d @@ -17,6 +17,7 @@ #include "ecl.h" #include "page.h" #include "internal.h" +#include "bytecodes.h" #ifndef GBC_BOEHM @@ -331,7 +332,7 @@ BEGIN: mark_object(x->bytecodes.lex); mark_object(x->bytecodes.specials); mark_object(x->bytecodes.definition); - mark_contblock(x->bytecodes.code, x->bytecodes.code_size); + mark_contblock(x->bytecodes.code, x->bytecodes.code_size * sizeof(cl_opcode)); p = x->bytecodes.data; i = x->bytecodes.data_size; goto MARK_DATA; @@ -692,6 +693,8 @@ ecl_gc(cl_type t) if (!GC_enabled()) return; + CL_SAVE_ENVIRONMENT; + if (SYM_VAL(@'si::*gc-verbose*') != Cnil) { printf("\n[GC .."); /* To use this should add entries in tm_table for reloc and contig. @@ -827,6 +830,8 @@ ecl_gc(cl_type t) if (GC_exit_hook != NULL) (*GC_exit_hook)(); + CL_RESTORE_ENVIRONMENT; + #ifdef THREADS /* diff --git a/src/h/stacks.h b/src/h/stacks.h index 463457b39..ba165194a 100644 --- a/src/h/stacks.h +++ b/src/h/stacks.h @@ -231,6 +231,14 @@ extern cl_object lex_env; * HIGH LEVEL CONTROL STRUCTURES * *********************************/ +#define CL_NEWENV_BEGIN {\ + int __i = cl_stack_push_values(); \ + cl_object __env = lex_env; + +#define CL_NEWENV_END \ + cl_stack_pop_values(__i); \ + lex_env = __env; } + #define CL_UNWIND_PROTECT_BEGIN {\ bool __unwinding; frame_ptr __next_fr; \ cl_index __nr; \