From 4343420d4d559a7d4cdacdbc1fd61552dcf59f04 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 4 Oct 1999 15:51:04 -0200 Subject: simplified version of `gc' tag method (only for userdata now). --- lfunc.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'lfunc.c') diff --git a/lfunc.c b/lfunc.c index 32fefb29..ea8a9a42 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 1.10 1999/03/04 21:17:26 roberto Exp roberto $ +** $Id: lfunc.c,v 1.11 1999/08/16 20:52:00 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -18,7 +18,9 @@ Closure *luaF_newclosure (int nelems) { Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject)); - luaO_insertlist(&(L->rootcl), (GCnode *)c); + c->next = L->rootcl; + L->rootcl = c; + c->marked = 0; L->nblocks += gcsizeclosure(c); c->nelems = nelems; return c; @@ -33,14 +35,16 @@ TProtoFunc *luaF_newproto (void) { f->consts = NULL; f->nconsts = 0; f->locvars = NULL; - luaO_insertlist(&(L->rootproto), (GCnode *)f); + f->next = L->rootproto; + L->rootproto = f; + f->marked = 0; L->nblocks += gcsizeproto(f); return f; } - -static void freefunc (TProtoFunc *f) { +void luaF_freeproto (TProtoFunc *f) { + L->nblocks -= gcsizeproto(f); luaM_free(f->code); luaM_free(f->locvars); luaM_free(f->consts); @@ -48,23 +52,9 @@ static void freefunc (TProtoFunc *f) { } -void luaF_freeproto (TProtoFunc *l) { - while (l) { - TProtoFunc *next = (TProtoFunc *)l->head.next; - L->nblocks -= gcsizeproto(l); - freefunc(l); - l = next; - } -} - - -void luaF_freeclosure (Closure *l) { - while (l) { - Closure *next = (Closure *)l->head.next; - L->nblocks -= gcsizeclosure(l); - luaM_free(l); - l = next; - } +void luaF_freeclosure (Closure *c) { + L->nblocks -= gcsizeclosure(c); + luaM_free(c); } -- cgit v1.2.3-55-g6feb