keep memory-error message in the global state, so that its use

does not depend on Lua internalizing strings to avoid a string
creation on memory errors
This commit is contained in:
Roberto Ierusalimschy 2010-04-08 14:16:46 -03:00
parent 28aa733c15
commit 055104f5b6
4 changed files with 13 additions and 9 deletions

6
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.81 2010/02/09 11:56:29 roberto Exp roberto $
** $Id: ldo.c,v 2.82 2010/03/26 20:58:11 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -83,8 +83,8 @@ struct lua_longjmp {
static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
switch (errcode) {
case LUA_ERRMEM: {
setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
case LUA_ERRMEM: { /* memory error? */
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
break;
}
case LUA_ERRERR: {

4
lmem.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lmem.h,v 1.34 2009/04/17 14:40:13 roberto Exp roberto $
** $Id: lmem.h,v 1.35 2009/12/16 16:42:58 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@ -13,8 +13,6 @@
#include "llimits.h"
#include "lua.h"
#define MEMERRMSG "not enough memory"
#define luaM_reallocv(L,b,on,n,e) \
((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.76 2010/03/29 17:43:14 roberto Exp roberto $
** $Id: lstate.c,v 2.77 2010/04/05 16:35:37 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -34,6 +34,9 @@
#endif
#define MEMERRMSG "not enough memory"
/*
** thread state + extra space
*/
@ -157,7 +160,9 @@ static void f_luaopen (lua_State *L, void *ud) {
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
luaT_init(L);
luaX_init(L);
luaS_fix(luaS_newliteral(L, MEMERRMSG));
/* pre-create memory-error message */
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
luaS_fix(g->memerrmsg); /* it should never be collected */
g->GCthreshold = 4*g->totalbytes;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.59 2010/03/29 17:43:14 roberto Exp roberto $
** $Id: lstate.h,v 2.60 2010/04/05 16:35:37 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -142,6 +142,7 @@ typedef struct global_State {
lua_CFunction panic; /* to be called in unprotected errors */
struct lua_State *mainthread;
const lua_Number *version; /* pointer to version number */
TString *memerrmsg; /* memory-error message */
TString *tmname[TM_N]; /* array with tag-method names */
struct Table *mt[NUM_TAGS]; /* metatables for basic types */
} global_State;