Browse Source

in case of memory allocation errors, sizecode and sizelineinfo can
be different

Roberto Ierusalimschy 23 years ago
parent
commit
c196348717
5 changed files with 14 additions and 11 deletions
  1. 4 4
      lcode.c
  2. 2 1
      ldebug.c
  3. 3 3
      lfunc.c
  4. 2 1
      lobject.h
  5. 3 2
      lparser.c

+ 4 - 4
lcode.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.c,v 1.110 2002/08/20 20:03:05 roberto Exp roberto $
+** $Id: lcode.c,v 1.111 2002/08/21 18:56:33 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -686,14 +686,14 @@ void luaK_fixline (FuncState *fs, int line) {
 
 int luaK_code (FuncState *fs, Instruction i, int line) {
   Proto *f = fs->f;
-  int oldsize = f->sizecode;
   luaK_dischargejpc(fs);  /* `pc' will change */
   /* put new instruction in code array */
   luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
                   MAX_INT, "code size overflow");
   f->code[fs->pc] = i;
-  if (f->sizecode != oldsize)
-    luaM_reallocvector(fs->L, f->lineinfo, oldsize, f->sizecode, int);
+  /* save corresponding line information */
+  luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
+                  MAX_INT, "code size overflow");
   f->lineinfo[fs->pc] = line;
   return fs->pc++;
 }

+ 2 - 1
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 1.133 2002/08/20 20:03:05 roberto Exp roberto $
+** $Id: ldebug.c,v 1.134 2002/09/05 19:45:42 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -248,6 +248,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
 
 static int precheck (const Proto *pt) {
   check(pt->maxstacksize <= MAXSTACK);
+  check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
   lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize);
   check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
   return 1;

+ 3 - 3
lfunc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.c,v 1.58 2002/08/16 14:45:55 roberto Exp roberto $
+** $Id: lfunc.c,v 1.59 2002/08/30 19:09:21 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -80,6 +80,7 @@ Proto *luaF_newproto (lua_State *L) {
   f->sizep = 0;
   f->code = NULL;
   f->sizecode = 0;
+  f->sizelineinfo = 0;
   f->nupvalues = 0;
   f->numparams = 0;
   f->is_vararg = 0;
@@ -95,8 +96,7 @@ Proto *luaF_newproto (lua_State *L) {
 
 void luaF_freeproto (lua_State *L, Proto *f) {
   luaM_freearray(L, f->code, f->sizecode, Instruction);
-  if (f->lineinfo)
-    luaM_freearray(L, f->lineinfo, f->sizecode, int);
+  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
   luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
   luaM_freearray(L, f->k, f->sizek, TObject);
   luaM_freearray(L, f->p, f->sizep, Proto *);

+ 2 - 1
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.146 2002/09/19 13:03:53 roberto Exp roberto $
+** $Id: lobject.h,v 1.147 2002/10/08 18:46:08 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -186,6 +186,7 @@ typedef struct Proto {
   TString  *source;
   int sizek;  /* size of `k' */
   int sizecode;
+  int sizelineinfo;
   int sizep;  /* size of `p' */
   int sizelocvars;
   int lineDefined;

+ 3 - 2
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.194 2002/08/30 19:09:21 roberto Exp roberto $
+** $Id: lparser.c,v 1.195 2002/10/08 18:46:08 roberto Exp roberto $
 ** Lua Parser
 ** See Copyright Notice in lua.h
 */
@@ -337,8 +337,9 @@ static void close_func (LexState *ls) {
   removevars(ls, 0);
   luaK_codeABC(fs, OP_RETURN, 0, 1, 0);  /* final return */
   luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
-  luaM_reallocvector(L, f->lineinfo, f->sizecode, fs->pc, int);
   f->sizecode = fs->pc;
+  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
+  f->sizelineinfo = fs->pc;
   luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject);
   f->sizek = fs->nk;
   luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);