From 7a35f23c1688e3e24781c780e121bbdc0e4b53e1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 21 Mar 1996 15:55:02 -0300 Subject: [PATCH] a simplification about memory error messages. --- func.c | 3 +-- luamem.c | 29 +++++------------------------ luamem.h | 15 ++++++++++----- opcode.c | 4 ++-- table.c | 7 +++---- 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/func.c b/func.c index d9ed9831..21b19a19 100644 --- a/func.c +++ b/func.c @@ -102,8 +102,7 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined) void luaI_registerlocalvar (TaggedString *varname, int line) { if (numcurrvars >= maxcurrvars) - maxcurrvars = growvector(&currvars, maxcurrvars, LocVar, - lockEM, MAX_WORD); + maxcurrvars = growvector(&currvars, maxcurrvars, LocVar, "", MAX_WORD); currvars[numcurrvars].varname = varname; currvars[numcurrvars].line = line; numcurrvars++; diff --git a/luamem.c b/luamem.c index 164cbca2..169255de 100644 --- a/luamem.c +++ b/luamem.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_mem = "$Id: mem.c,v 1.9 1996/03/14 15:55:49 roberto Exp roberto $"; +char *rcs_mem = "$Id: mem.c,v 1.10 1996/03/21 16:31:32 roberto Exp roberto $"; #include #include @@ -14,27 +14,8 @@ char *rcs_mem = "$Id: mem.c,v 1.9 1996/03/14 15:55:49 roberto Exp roberto $"; #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) -{ - Long recovered = luaI_collectgarbage(); /* try to collect garbage */ - if (recovered) - lua_error("not enough memory"); - else - { /* if there is no garbage then must exit */ - fprintf(stderr, "lua error: memory overflow - unable to recover\n"); - exit(1); - } -} +#define mem_error() lua_error(memEM) + void luaI_free (void *block) { @@ -66,10 +47,10 @@ void *luaI_realloc (void *oldblock, unsigned long size) int luaI_growvector (void **block, unsigned long nelems, int size, - enum memerrormsg errormsg, unsigned long limit) + char *errormsg, unsigned long limit) { if (nelems >= limit) - lua_error(luaI_memerrormsg[errormsg]); + lua_error(errormsg); nelems = (nelems == 0) ? 20 : nelems*2; if (nelems > limit) nelems = limit; diff --git a/luamem.h b/luamem.h index dc0e925b..d22cc200 100644 --- a/luamem.h +++ b/luamem.h @@ -1,7 +1,7 @@ /* ** mem.c ** memory manager for lua -** $Id: mem.h,v 1.4 1996/03/14 15:55:49 roberto Exp roberto $ +** $Id: mem.h,v 1.5 1996/03/21 16:31:32 roberto Exp roberto $ */ #ifndef mem_h @@ -13,9 +13,14 @@ /* memory error messages */ -#define NUMERRMSG 6 -enum memerrormsg {codeEM, symbolEM, constantEM, stackEM, lexEM, lockEM}; -extern char *luaI_memerrormsg[]; +#define codeEM "code size overflow" +#define symbolEM "symbol table overflow" +#define constantEM "constant table overflow" +#define stackEM "stack size overflow" +#define lexEM "lex buffer overflow" +#define lockEM "lock table overflow" +#define tableEM "table overflow" +#define memEM "not enough memory" void luaI_free (void *block); @@ -23,7 +28,7 @@ void *luaI_malloc (unsigned long size); void *luaI_realloc (void *oldblock, 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); + char *errormsg, unsigned long limit); #define new(s) ((s *)luaI_malloc(sizeof(s))) #define newvector(n,s) ((s *)luaI_malloc((n)*sizeof(s))) diff --git a/opcode.c b/opcode.c index c7db7824..539f2cf3 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.63 1996/03/20 17:05:44 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.64 1996/03/21 16:31:32 roberto Exp roberto $"; #include #include @@ -102,7 +102,7 @@ static void growstack (void) if (stacksize >= limit) { limit = stacksize; - lua_error(luaI_memerrormsg[stackEM]); + lua_error(stackEM); } } } diff --git a/table.c b/table.c index 3920ed19..6c77d2e9 100644 --- a/table.c +++ b/table.c @@ -3,7 +3,7 @@ ** Module to control static tables */ -char *rcs_table="$Id: table.c,v 2.49 1996/03/14 15:57:19 roberto Exp roberto $"; +char *rcs_table="$Id: table.c,v 2.50 1996/03/21 16:31:32 roberto Exp roberto $"; #include "mem.h" #include "opcode.h" @@ -75,12 +75,11 @@ void luaI_initsymbol (void) */ void luaI_initconstant (void) { - int i; lua_maxconstant = BUFFER_BLOCK; lua_constant = newvector(lua_maxconstant, TaggedString *); /* pre-register mem error messages, to avoid loop when error arises */ - for (i=0; i