1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

a simplification about memory error messages.

This commit is contained in:
Roberto Ierusalimschy 1996-03-21 15:55:02 -03:00
parent 9284742a11
commit 7a35f23c16
5 changed files with 21 additions and 37 deletions

3
func.c
View File

@ -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++;

View File

@ -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 <stdlib.h>
#include <string.h>
@ -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;

View File

@ -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)))

View File

@ -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 <setjmp.h>
#include <stdio.h>
@ -102,7 +102,7 @@ static void growstack (void)
if (stacksize >= limit)
{
limit = stacksize;
lua_error(luaI_memerrormsg[stackEM]);
lua_error(stackEM);
}
}
}

View File

@ -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<NUMERRMSG; i++)
luaI_findconstantbyname(luaI_memerrormsg[i]);
luaI_findconstantbyname(tableEM);
luaI_findconstantbyname(memEM);
}