klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit b35a510b715d14e024eae9f292df7187ccaf5ab3
parent 3dc00c1ca306e8be292e6dc16ffee7bb9ca75696
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri, 15 Apr 2011 17:02:12 -0300

Added GC rooting to pairs, ports and promises.

Diffstat:
Msrc/kpair.c | 4++++
Msrc/kport.c | 6++++++
Msrc/kpromise.c | 12+++++++++++-
3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/kpair.c b/src/kpair.c @@ -12,7 +12,11 @@ TValue kcons_g(klisp_State *K, bool m, TValue car, TValue cdr) { + krooted_tvs_push(K, car); + krooted_tvs_push(K, cdr); Pair *new_pair = klispM_new(K, Pair); + krooted_tvs_pop(K); + krooted_tvs_pop(K); /* header + gc_fields */ klispC_link(K, (GCObject *) new_pair, K_TPAIR, (m? 0 : K_FLAG_IMMUTABLE)); diff --git a/src/kport.c b/src/kport.c @@ -38,7 +38,13 @@ TValue kmake_port(klisp_State *K, TValue filename, bool writep, TValue name, TValue kmake_std_port(klisp_State *K, TValue filename, bool writep, TValue name, TValue si, FILE *file) { + krooted_tvs_push(K, filename); + krooted_tvs_push(K, name); + krooted_tvs_push(K, si); Port *new_port = klispM_new(K, Port); + krooted_tvs_pop(K); + krooted_tvs_pop(K); + krooted_tvs_pop(K); /* header + gc_fields */ klispC_link(K, (GCObject *) new_port, K_TPORT, diff --git a/src/kpromise.c b/src/kpromise.c @@ -14,7 +14,15 @@ TValue kmake_promise(klisp_State *K, TValue name, TValue si, TValue exp, TValue maybe_env) { + krooted_tvs_push(K, name); + krooted_tvs_push(K, si); + krooted_tvs_push(K, exp); + krooted_tvs_push(K, maybe_env); Promise *new_prom = klispM_new(K, Promise); + krooted_tvs_pop(K); + krooted_tvs_pop(K); + krooted_tvs_pop(K); + krooted_tvs_pop(K); /* header + gc_fields */ klispC_link(K, (GCObject *) new_prom, K_TPROMISE, 0); @@ -22,7 +30,9 @@ TValue kmake_promise(klisp_State *K, TValue name, TValue si, /* promise specific fields */ new_prom->name = name; new_prom->si = si; - /* GC: root new_prom before cons */ + new_prom->node = KNIL; /* temp in case of GC */ + krooted_tvs_push(K, gc2prom(new_prom)); new_prom->node = kcons(K, exp, maybe_env); + krooted_tvs_pop(K); return gc2prom(new_prom); }