aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-16 17:40:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-10-16 17:40:58 -0300
commitc196348717dfda116726145220e5d1311547980e (patch)
tree83149c29559b888eed7a28e5f1558a67a912cf90
parent669129a6d8210e758ba94ea2786a370946572f7d (diff)
downloadlua-c196348717dfda116726145220e5d1311547980e.tar.gz
lua-c196348717dfda116726145220e5d1311547980e.tar.bz2
lua-c196348717dfda116726145220e5d1311547980e.zip
in case of memory allocation errors, sizecode and sizelineinfo can
be different
-rw-r--r--lcode.c8
-rw-r--r--ldebug.c3
-rw-r--r--lfunc.c6
-rw-r--r--lobject.h3
-rw-r--r--lparser.c5
5 files changed, 14 insertions, 11 deletions
diff --git a/lcode.c b/lcode.c
index 118f16b3..e3420ac1 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.110 2002/08/20 20:03:05 roberto Exp roberto $ 2** $Id: lcode.c,v 1.111 2002/08/21 18:56:33 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -686,14 +686,14 @@ void luaK_fixline (FuncState *fs, int line) {
686 686
687int luaK_code (FuncState *fs, Instruction i, int line) { 687int luaK_code (FuncState *fs, Instruction i, int line) {
688 Proto *f = fs->f; 688 Proto *f = fs->f;
689 int oldsize = f->sizecode;
690 luaK_dischargejpc(fs); /* `pc' will change */ 689 luaK_dischargejpc(fs); /* `pc' will change */
691 /* put new instruction in code array */ 690 /* put new instruction in code array */
692 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, 691 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
693 MAX_INT, "code size overflow"); 692 MAX_INT, "code size overflow");
694 f->code[fs->pc] = i; 693 f->code[fs->pc] = i;
695 if (f->sizecode != oldsize) 694 /* save corresponding line information */
696 luaM_reallocvector(fs->L, f->lineinfo, oldsize, f->sizecode, int); 695 luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
696 MAX_INT, "code size overflow");
697 f->lineinfo[fs->pc] = line; 697 f->lineinfo[fs->pc] = line;
698 return fs->pc++; 698 return fs->pc++;
699} 699}
diff --git a/ldebug.c b/ldebug.c
index 0cf0f963..764134d9 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.133 2002/08/20 20:03:05 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.134 2002/09/05 19:45:42 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -248,6 +248,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
248 248
249static int precheck (const Proto *pt) { 249static int precheck (const Proto *pt) {
250 check(pt->maxstacksize <= MAXSTACK); 250 check(pt->maxstacksize <= MAXSTACK);
251 check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
251 lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize); 252 lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize);
252 check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN); 253 check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
253 return 1; 254 return 1;
diff --git a/lfunc.c b/lfunc.c
index ebdfa086..d20424b5 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.58 2002/08/16 14:45:55 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.59 2002/08/30 19:09:21 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*/
@@ -80,6 +80,7 @@ Proto *luaF_newproto (lua_State *L) {
80 f->sizep = 0; 80 f->sizep = 0;
81 f->code = NULL; 81 f->code = NULL;
82 f->sizecode = 0; 82 f->sizecode = 0;
83 f->sizelineinfo = 0;
83 f->nupvalues = 0; 84 f->nupvalues = 0;
84 f->numparams = 0; 85 f->numparams = 0;
85 f->is_vararg = 0; 86 f->is_vararg = 0;
@@ -95,8 +96,7 @@ Proto *luaF_newproto (lua_State *L) {
95 96
96void luaF_freeproto (lua_State *L, Proto *f) { 97void luaF_freeproto (lua_State *L, Proto *f) {
97 luaM_freearray(L, f->code, f->sizecode, Instruction); 98 luaM_freearray(L, f->code, f->sizecode, Instruction);
98 if (f->lineinfo) 99 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
99 luaM_freearray(L, f->lineinfo, f->sizecode, int);
100 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); 100 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
101 luaM_freearray(L, f->k, f->sizek, TObject); 101 luaM_freearray(L, f->k, f->sizek, TObject);
102 luaM_freearray(L, f->p, f->sizep, Proto *); 102 luaM_freearray(L, f->p, f->sizep, Proto *);
diff --git a/lobject.h b/lobject.h
index c872ecc9..ba81d56d 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.146 2002/09/19 13:03:53 roberto Exp roberto $ 2** $Id: lobject.h,v 1.147 2002/10/08 18:46:08 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -186,6 +186,7 @@ typedef struct Proto {
186 TString *source; 186 TString *source;
187 int sizek; /* size of `k' */ 187 int sizek; /* size of `k' */
188 int sizecode; 188 int sizecode;
189 int sizelineinfo;
189 int sizep; /* size of `p' */ 190 int sizep; /* size of `p' */
190 int sizelocvars; 191 int sizelocvars;
191 int lineDefined; 192 int lineDefined;
diff --git a/lparser.c b/lparser.c
index 1009f87b..26f079f2 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.194 2002/08/30 19:09:21 roberto Exp roberto $ 2** $Id: lparser.c,v 1.195 2002/10/08 18:46:08 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -337,8 +337,9 @@ static void close_func (LexState *ls) {
337 removevars(ls, 0); 337 removevars(ls, 0);
338 luaK_codeABC(fs, OP_RETURN, 0, 1, 0); /* final return */ 338 luaK_codeABC(fs, OP_RETURN, 0, 1, 0); /* final return */
339 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); 339 luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
340 luaM_reallocvector(L, f->lineinfo, f->sizecode, fs->pc, int);
341 f->sizecode = fs->pc; 340 f->sizecode = fs->pc;
341 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
342 f->sizelineinfo = fs->pc;
342 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); 343 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject);
343 f->sizek = fs->nk; 344 f->sizek = fs->nk;
344 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); 345 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);