better control when growing arrays.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_fallback="$Id: fallback.c,v 1.21 1996/03/04 13:29:10 roberto Exp roberto $";
|
char *rcs_fallback="$Id: fallback.c,v 1.22 1996/03/19 22:28:37 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -132,8 +132,7 @@ int luaI_lock (Object *object)
|
|||||||
}
|
}
|
||||||
/* no more empty spaces */
|
/* no more empty spaces */
|
||||||
oldSize = lockSize;
|
oldSize = lockSize;
|
||||||
lockSize = (lockSize == 0) ? 10 : 3*lockSize/2 + 5;
|
lockSize = growvector(&lockArray, lockSize, Object, lockEM, MAX_WORD);
|
||||||
lockArray = growvector(lockArray, lockSize, Object);
|
|
||||||
for (i=oldSize; i<lockSize; i++)
|
for (i=oldSize; i<lockSize; i++)
|
||||||
tag(&lockArray[i]) = LUA_T_NIL;
|
tag(&lockArray[i]) = LUA_T_NIL;
|
||||||
lockArray[oldSize] = *object;
|
lockArray[oldSize] = *object;
|
||||||
|
|||||||
7
func.c
7
func.c
@@ -6,7 +6,6 @@
|
|||||||
#include "func.h"
|
#include "func.h"
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
|
|
||||||
#define LOCALVARINITSIZE 10
|
|
||||||
|
|
||||||
static TFunc *function_root = NULL;
|
static TFunc *function_root = NULL;
|
||||||
static LocVar *currvars = NULL;
|
static LocVar *currvars = NULL;
|
||||||
@@ -103,10 +102,8 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
|
|||||||
void luaI_registerlocalvar (TaggedString *varname, int line)
|
void luaI_registerlocalvar (TaggedString *varname, int line)
|
||||||
{
|
{
|
||||||
if (numcurrvars >= maxcurrvars)
|
if (numcurrvars >= maxcurrvars)
|
||||||
{
|
maxcurrvars = growvector(&currvars, maxcurrvars, LocVar,
|
||||||
maxcurrvars = (maxcurrvars == 0) ? LOCALVARINITSIZE : maxcurrvars*2;
|
lockEM, MAX_WORD);
|
||||||
currvars = growvector(currvars, maxcurrvars, LocVar);
|
|
||||||
}
|
|
||||||
currvars[numcurrvars].varname = varname;
|
currvars[numcurrvars].varname = varname;
|
||||||
currvars[numcurrvars].line = line;
|
currvars[numcurrvars].line = line;
|
||||||
numcurrvars++;
|
numcurrvars++;
|
||||||
|
|||||||
5
lex.c
5
lex.c
@@ -1,4 +1,4 @@
|
|||||||
char *rcs_lex = "$Id: lex.c,v 2.30 1996/03/14 15:17:28 roberto Exp roberto $";
|
char *rcs_lex = "$Id: lex.c,v 2.31 1996/03/19 16:50:24 roberto Exp roberto $";
|
||||||
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -83,8 +83,7 @@ void luaI_addReserved (void)
|
|||||||
static void growtext (void)
|
static void growtext (void)
|
||||||
{
|
{
|
||||||
int size = yytextLast - yytext;
|
int size = yytextLast - yytext;
|
||||||
textsize *= 2;
|
textsize = growvector(&yytext, textsize, char, lexEM, MAX_WORD);
|
||||||
yytext = growvector(yytext, textsize, char);
|
|
||||||
yytextLast = yytext + size;
|
yytextLast = yytext + size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
lua.stx
13
lua.stx
@@ -1,6 +1,6 @@
|
|||||||
%{
|
%{
|
||||||
|
|
||||||
char *rcs_luastx = "$Id: lua.stx,v 3.34 1996/02/26 21:00:27 roberto Exp roberto $";
|
char *rcs_luastx = "$Id: lua.stx,v 3.35 1996/03/08 12:02:37 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -31,7 +31,7 @@ int yyparse (void);
|
|||||||
#endif
|
#endif
|
||||||
static int maxcode;
|
static int maxcode;
|
||||||
static int maxmain;
|
static int maxmain;
|
||||||
static Long maxcurr; /* to allow maxcurr *= 2 without overflow */
|
static int maxcurr;
|
||||||
static Byte *funcCode = NULL;
|
static Byte *funcCode = NULL;
|
||||||
static Byte **initcode;
|
static Byte **initcode;
|
||||||
static Byte *basepc;
|
static Byte *basepc;
|
||||||
@@ -70,14 +70,7 @@ static void yyerror (char *s)
|
|||||||
static void code_byte (Byte c)
|
static void code_byte (Byte c)
|
||||||
{
|
{
|
||||||
if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */
|
if (pc>maxcurr-2) /* 1 byte free to code HALT of main code */
|
||||||
{
|
maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
|
||||||
if (maxcurr >= MAX_INT)
|
|
||||||
yyerror("code size overflow");
|
|
||||||
maxcurr *= 2;
|
|
||||||
if (maxcurr >= MAX_INT)
|
|
||||||
maxcurr = MAX_INT;
|
|
||||||
basepc = growvector(basepc, maxcurr, Byte);
|
|
||||||
}
|
|
||||||
basepc[pc++] = c;
|
basepc[pc++] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
luamem.c
26
luamem.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_mem = "$Id: mem.c,v 1.8 1996/02/22 20:34:33 roberto Exp roberto $";
|
char *rcs_mem = "$Id: mem.c,v 1.9 1996/03/14 15:55:49 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -13,6 +13,17 @@ char *rcs_mem = "$Id: mem.c,v 1.8 1996/02/22 20:34:33 roberto Exp roberto $";
|
|||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
|
||||||
|
|
||||||
|
char *luaI_memerrormsg[NUMERRMSG] = {
|
||||||
|
"code size overflow",
|
||||||
|
"symbol table overflow",
|
||||||
|
"constant table overflow",
|
||||||
|
"stack size overflow",
|
||||||
|
"lex buffer overflow",
|
||||||
|
"lock table overflow"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void mem_error (void)
|
static void mem_error (void)
|
||||||
{
|
{
|
||||||
Long recovered = luaI_collectgarbage(); /* try to collect garbage */
|
Long recovered = luaI_collectgarbage(); /* try to collect garbage */
|
||||||
@@ -54,6 +65,19 @@ void *luaI_realloc (void *oldblock, unsigned long size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int luaI_growvector (void **block, unsigned long nelems, int size,
|
||||||
|
enum memerrormsg errormsg, unsigned long limit)
|
||||||
|
{
|
||||||
|
if (nelems >= limit)
|
||||||
|
lua_error(luaI_memerrormsg[errormsg]);
|
||||||
|
nelems = (nelems == 0) ? 20 : nelems*2;
|
||||||
|
if (nelems > limit)
|
||||||
|
nelems = limit;
|
||||||
|
*block = luaI_realloc(*block, nelems*size);
|
||||||
|
return (int) nelems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void* luaI_buffer (unsigned long size)
|
void* luaI_buffer (unsigned long size)
|
||||||
{
|
{
|
||||||
static unsigned long buffsize = 0;
|
static unsigned long buffsize = 0;
|
||||||
|
|||||||
16
luamem.h
16
luamem.h
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** mem.c
|
** mem.c
|
||||||
** memory manager for lua
|
** memory manager for lua
|
||||||
** $Id: mem.h,v 1.3 1996/02/22 20:34:33 roberto Exp roberto $
|
** $Id: mem.h,v 1.4 1996/03/14 15:55:49 roberto Exp roberto $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef mem_h
|
#ifndef mem_h
|
||||||
@@ -11,14 +11,24 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* memory error messages */
|
||||||
|
#define NUMERRMSG 6
|
||||||
|
enum memerrormsg {codeEM, symbolEM, constantEM, stackEM, lexEM, lockEM};
|
||||||
|
extern char *luaI_memerrormsg[];
|
||||||
|
|
||||||
|
|
||||||
void luaI_free (void *block);
|
void luaI_free (void *block);
|
||||||
void *luaI_malloc (unsigned long size);
|
void *luaI_malloc (unsigned long size);
|
||||||
void *luaI_realloc (void *oldblock, unsigned long size);
|
void *luaI_realloc (void *oldblock, unsigned long size);
|
||||||
void* luaI_buffer (unsigned long size);
|
void *luaI_buffer (unsigned long size);
|
||||||
|
int luaI_growvector (void **block, unsigned long nelems, int size,
|
||||||
|
enum memerrormsg errormsg, unsigned long limit);
|
||||||
|
|
||||||
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
#define new(s) ((s *)luaI_malloc(sizeof(s)))
|
||||||
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
#define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s)))
|
||||||
#define growvector(old,n,s) ((s *)luaI_realloc(old,(n)*sizeof(s)))
|
#define growvector(old,n,s,e,l) \
|
||||||
|
(luaI_growvector((void**)old,n,sizeof(s),e,l))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
17
opcode.c
17
opcode.c
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_opcode="$Id: opcode.c,v 3.62 1996/03/19 22:28:37 roberto Exp roberto $";
|
char *rcs_opcode="$Id: opcode.c,v 3.63 1996/03/20 17:05:44 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -93,14 +93,17 @@ static void growstack (void)
|
|||||||
lua_initstack();
|
lua_initstack();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
static int limit = 10000;
|
||||||
StkId t = top-stack;
|
StkId t = top-stack;
|
||||||
Long maxstack = stackLimit - stack;
|
Long stacksize = stackLimit - stack;
|
||||||
maxstack *= 2;
|
stacksize = growvector(&stack, stacksize, Object, stackEM, limit+100);
|
||||||
stack = growvector(stack, maxstack, Object);
|
stackLimit = stack+stacksize;
|
||||||
stackLimit = stack+maxstack;
|
|
||||||
top = stack + t;
|
top = stack + t;
|
||||||
if (maxstack >= MAX_WORD/2)
|
if (stacksize >= limit)
|
||||||
lua_error("stack size overflow");
|
{
|
||||||
|
limit = stacksize;
|
||||||
|
lua_error(luaI_memerrormsg[stackEM]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
table.c
29
table.c
@@ -3,7 +3,7 @@
|
|||||||
** Module to control static tables
|
** Module to control static tables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_table="$Id: table.c,v 2.48 1996/02/26 21:00:27 roberto Exp roberto $";
|
char *rcs_table="$Id: table.c,v 2.49 1996/03/14 15:57:19 roberto Exp roberto $";
|
||||||
|
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
@@ -33,7 +33,7 @@ static Long lua_maxconstant = 0;
|
|||||||
static void lua_nextvar (void);
|
static void lua_nextvar (void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Initialise symbol table with internal functions
|
** Internal functions
|
||||||
*/
|
*/
|
||||||
static struct {
|
static struct {
|
||||||
char *name;
|
char *name;
|
||||||
@@ -56,6 +56,7 @@ static struct {
|
|||||||
|
|
||||||
#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0]))
|
#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0]))
|
||||||
|
|
||||||
|
|
||||||
void luaI_initsymbol (void)
|
void luaI_initsymbol (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -74,8 +75,12 @@ void luaI_initsymbol (void)
|
|||||||
*/
|
*/
|
||||||
void luaI_initconstant (void)
|
void luaI_initconstant (void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
lua_maxconstant = BUFFER_BLOCK;
|
lua_maxconstant = BUFFER_BLOCK;
|
||||||
lua_constant = newvector(lua_maxconstant, TaggedString *);
|
lua_constant = newvector(lua_maxconstant, TaggedString *);
|
||||||
|
/* pre-register mem error messages, to avoid loop when error arises */
|
||||||
|
for (i=0; i<NUMERRMSG; i++)
|
||||||
|
luaI_findconstantbyname(luaI_memerrormsg[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,14 +93,8 @@ Word luaI_findsymbol (TaggedString *t)
|
|||||||
if (t->varindex == NOT_USED)
|
if (t->varindex == NOT_USED)
|
||||||
{
|
{
|
||||||
if (lua_ntable == lua_maxsymbol)
|
if (lua_ntable == lua_maxsymbol)
|
||||||
{
|
lua_maxsymbol = growvector(&lua_table, lua_maxsymbol, Symbol,
|
||||||
if (lua_maxsymbol >= MAX_WORD)
|
symbolEM, MAX_WORD);
|
||||||
lua_error("symbol table overflow");
|
|
||||||
lua_maxsymbol *= 2;
|
|
||||||
if (lua_maxsymbol >= MAX_WORD)
|
|
||||||
lua_maxsymbol = MAX_WORD;
|
|
||||||
lua_table = growvector(lua_table, lua_maxsymbol, Symbol);
|
|
||||||
}
|
|
||||||
t->varindex = lua_ntable;
|
t->varindex = lua_ntable;
|
||||||
lua_table[lua_ntable].varname = t;
|
lua_table[lua_ntable].varname = t;
|
||||||
s_tag(lua_ntable) = LUA_T_NIL;
|
s_tag(lua_ntable) = LUA_T_NIL;
|
||||||
@@ -120,14 +119,8 @@ Word luaI_findconstant (TaggedString *t)
|
|||||||
if (t->constindex == NOT_USED)
|
if (t->constindex == NOT_USED)
|
||||||
{
|
{
|
||||||
if (lua_nconstant == lua_maxconstant)
|
if (lua_nconstant == lua_maxconstant)
|
||||||
{
|
lua_maxconstant = growvector(&lua_constant, lua_maxconstant, TaggedString *,
|
||||||
if (lua_maxconstant >= MAX_WORD)
|
constantEM, MAX_WORD);
|
||||||
lua_error("constant table overflow");
|
|
||||||
lua_maxconstant *= 2;
|
|
||||||
if (lua_maxconstant >= MAX_WORD)
|
|
||||||
lua_maxconstant = MAX_WORD;
|
|
||||||
lua_constant = growvector(lua_constant, lua_maxconstant, TaggedString *);
|
|
||||||
}
|
|
||||||
t->constindex = lua_nconstant;
|
t->constindex = lua_nconstant;
|
||||||
lua_constant[lua_nconstant] = t;
|
lua_constant[lua_nconstant] = t;
|
||||||
lua_nconstant++;
|
lua_nconstant++;
|
||||||
|
|||||||
Reference in New Issue
Block a user