summaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 10:55:41 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 10:55:41 -0200
commit0183b8030c80f57b87874ff7867ccdb172d9d3dc (patch)
tree1033b5a84489a2f1f1bd210b1b120155cd7aeed7 /lstate.c
parent8c49e198654567f770a7d5081b886a7c35201d81 (diff)
downloadlua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.gz
lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.bz2
lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.zip
`free' gets size of the block: complete control over memory use
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/lstate.c b/lstate.c
index 90ee5cb3..7ed79b50 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.48 2000/10/30 16:29:59 roberto Exp roberto $ 2** $Id: lstate.c,v 1.49 2000/12/26 18:46:09 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -58,8 +58,8 @@ static void f_luaopen (lua_State *L, void *ud) {
58#ifdef LUA_DEBUG 58#ifdef LUA_DEBUG
59 luaB_opentests(L); 59 luaB_opentests(L);
60 if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ 60 if (lua_state == NULL) lua_state = L; /* keep first state to be opened */
61#endif
62 LUA_ASSERT(lua_gettop(L) == 0, "wrong API stack"); 61 LUA_ASSERT(lua_gettop(L) == 0, "wrong API stack");
62#endif
63} 63}
64 64
65 65
@@ -67,10 +67,10 @@ LUA_API lua_State *lua_open (int stacksize) {
67 lua_State *L = luaM_new(NULL, lua_State); 67 lua_State *L = luaM_new(NULL, lua_State);
68 if (L == NULL) return NULL; /* memory allocation error */ 68 if (L == NULL) return NULL; /* memory allocation error */
69 L->stack = NULL; 69 L->stack = NULL;
70 L->stacksize = 0;
70 L->strt.size = L->udt.size = 0; 71 L->strt.size = L->udt.size = 0;
71 L->strt.nuse = L->udt.nuse = 0; 72 L->strt.nuse = L->udt.nuse = 0;
72 L->strt.hash = NULL; 73 L->strt.hash = L->udt.hash = NULL;
73 L->udt.hash = NULL;
74 L->Mbuffer = NULL; 74 L->Mbuffer = NULL;
75 L->Mbuffsize = 0; 75 L->Mbuffsize = 0;
76 L->rootproto = NULL; 76 L->rootproto = NULL;
@@ -106,17 +106,12 @@ LUA_API void lua_close (lua_State *L) {
106 LUA_ASSERT(L->rootcl == NULL, "list should be empty"); 106 LUA_ASSERT(L->rootcl == NULL, "list should be empty");
107 LUA_ASSERT(L->roottable == NULL, "list should be empty"); 107 LUA_ASSERT(L->roottable == NULL, "list should be empty");
108 luaS_freeall(L); 108 luaS_freeall(L);
109 if (L->stack) 109 luaM_freearray(L, L->stack, L->stacksize, TObject);
110 L->nblocks -= (L->stack_last - L->stack + 1)*sizeof(TObject); 110 luaM_freearray(L, L->TMtable, L->sizeTM, struct TM);
111 luaM_free(L, L->stack); 111 luaM_freearray(L, L->refArray, L->sizeref, struct Ref);
112 L->nblocks -= L->ntag*sizeof(struct TM); 112 luaM_freearray(L, L->Mbuffer, L->Mbuffsize, char);
113 luaM_free(L, L->TMtable);
114 L->nblocks -= (L->nref)*sizeof(struct Ref);
115 luaM_free(L, L->refArray);
116 L->nblocks -= (L->Mbuffsize)*sizeof(char);
117 luaM_free(L, L->Mbuffer);
118 LUA_ASSERT(L->nblocks == sizeof(lua_State), "wrong count for nblocks"); 113 LUA_ASSERT(L->nblocks == sizeof(lua_State), "wrong count for nblocks");
119 luaM_free(L, L); 114 luaM_freelem(L, L, lua_State);
120 LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); 115 LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!");
121 LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); 116 LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!");
122} 117}