diff --git a/src/blua/ldo.c b/src/blua/ldo.c index 1bda07f11..54d7e654d 100644 --- a/src/blua/ldo.c +++ b/src/blua/ldo.c @@ -55,8 +55,8 @@ struct lua_longjmp { void luaD_seterrorobj (lua_State *L, int lerrcode, StkId oldtop) { switch (lerrcode) { - 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: { diff --git a/src/blua/lmem.h b/src/blua/lmem.h index ebfc22747..bc1b89575 100644 --- a/src/blua/lmem.h +++ b/src/blua/lmem.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 */ \ diff --git a/src/blua/lstate.c b/src/blua/lstate.c index f6265768b..b3482c6d6 100644 --- a/src/blua/lstate.c +++ b/src/blua/lstate.c @@ -64,6 +64,9 @@ static void freestack (lua_State *L, lua_State *L1) { } +#define MEMERRMSG "not enough memory" + + /* ** open parts that may cause memory-allocation errors */ @@ -76,7 +79,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; } diff --git a/src/blua/lstate.h b/src/blua/lstate.h index 2d97fe30a..7cfafdb94 100644 --- a/src/blua/lstate.h +++ b/src/blua/lstate.h @@ -89,6 +89,7 @@ typedef struct global_State { TValue l_registry; struct lua_State *mainthread; UpVal uvhead; /* head of double-linked list of all open upvalues */ + TString *memerrmsg; /* memory-error message */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */ TString *tmname[TM_N]; /* array with tag-method names */ } global_State;