aboutsummaryrefslogtreecommitdiff
path: root/lfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lfunc.c')
-rw-r--r--lfunc.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/lfunc.c b/lfunc.c
index 67aa23d4..46325dea 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.13 1999/10/14 19:46:57 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.14 1999/11/10 15:39:35 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -7,28 +7,30 @@
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9 9
10#define LUA_REENTRANT
11
10#include "lfunc.h" 12#include "lfunc.h"
11#include "lmem.h" 13#include "lmem.h"
12#include "lstate.h" 14#include "lstate.h"
13 15
14#define gcsizeproto(p) numblocks(0, sizeof(TProtoFunc)) 16#define gcsizeproto(L, p) numblocks(L, 0, sizeof(TProtoFunc))
15#define gcsizeclosure(c) numblocks(c->nelems, sizeof(Closure)) 17#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure))
16 18
17 19
18 20
19Closure *luaF_newclosure (int nelems) { 21Closure *luaF_newclosure (lua_State *L, int nelems) {
20 Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject)); 22 Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure)+nelems*sizeof(TObject));
21 c->next = L->rootcl; 23 c->next = L->rootcl;
22 L->rootcl = c; 24 L->rootcl = c;
23 c->marked = 0; 25 c->marked = 0;
24 c->nelems = nelems; 26 c->nelems = nelems;
25 L->nblocks += gcsizeclosure(c); 27 L->nblocks += gcsizeclosure(L, c);
26 return c; 28 return c;
27} 29}
28 30
29 31
30TProtoFunc *luaF_newproto (void) { 32TProtoFunc *luaF_newproto (lua_State *L) {
31 TProtoFunc *f = luaM_new(TProtoFunc); 33 TProtoFunc *f = luaM_new(L, TProtoFunc);
32 f->code = NULL; 34 f->code = NULL;
33 f->lineDefined = 0; 35 f->lineDefined = 0;
34 f->source = NULL; 36 f->source = NULL;
@@ -38,23 +40,23 @@ TProtoFunc *luaF_newproto (void) {
38 f->next = L->rootproto; 40 f->next = L->rootproto;
39 L->rootproto = f; 41 L->rootproto = f;
40 f->marked = 0; 42 f->marked = 0;
41 L->nblocks += gcsizeproto(f); 43 L->nblocks += gcsizeproto(L, f);
42 return f; 44 return f;
43} 45}
44 46
45 47
46void luaF_freeproto (TProtoFunc *f) { 48void luaF_freeproto (lua_State *L, TProtoFunc *f) {
47 L->nblocks -= gcsizeproto(f); 49 L->nblocks -= gcsizeproto(L, f);
48 luaM_free(f->code); 50 luaM_free(L, f->code);
49 luaM_free(f->locvars); 51 luaM_free(L, f->locvars);
50 luaM_free(f->consts); 52 luaM_free(L, f->consts);
51 luaM_free(f); 53 luaM_free(L, f);
52} 54}
53 55
54 56
55void luaF_freeclosure (Closure *c) { 57void luaF_freeclosure (lua_State *L, Closure *c) {
56 L->nblocks -= gcsizeclosure(c); 58 L->nblocks -= gcsizeclosure(L, c);
57 luaM_free(c); 59 luaM_free(L, c);
58} 60}
59 61
60 62