mirror of
https://github.com/lua/lua
synced 2024-11-22 12:51:30 +03:00
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:
parent
28aa733c15
commit
055104f5b6
6
ldo.c
6
ldo.c
@ -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
4
lmem.h
@ -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 */ \
|
||||
|
9
lstate.c
9
lstate.c
@ -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;
|
||||
}
|
||||
|
||||
|
3
lstate.h
3
lstate.h
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user