diff options
| -rw-r--r-- | lapi.c | 2 | ||||
| -rw-r--r-- | lmem.c | 4 | ||||
| -rw-r--r-- | lstate.c | 6 | ||||
| -rw-r--r-- | lstate.h | 6 |
4 files changed, 11 insertions, 7 deletions
| @@ -39,7 +39,7 @@ const char lua_ident[] = | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | /* | 41 | /* |
| 42 | ** Test for a valid index. | 42 | ** Test for a valid index (one that is not the 'nilvalue'). |
| 43 | ** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed. | 43 | ** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed. |
| 44 | ** However, it covers the most common cases in a faster way. | 44 | ** However, it covers the most common cases in a faster way. |
| 45 | */ | 45 | */ |
| @@ -29,7 +29,7 @@ | |||
| 29 | ** a full GC cycle at every allocation.) | 29 | ** a full GC cycle at every allocation.) |
| 30 | */ | 30 | */ |
| 31 | static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { | 31 | static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { |
| 32 | if (ttisnil(&g->nilvalue) && ns > os) | 32 | if (completestate(g) && ns > os) |
| 33 | return NULL; /* fail */ | 33 | return NULL; /* fail */ |
| 34 | else /* normal allocation */ | 34 | else /* normal allocation */ |
| 35 | return (*g->frealloc)(g->ud, block, os, ns); | 35 | return (*g->frealloc)(g->ud, block, os, ns); |
| @@ -146,7 +146,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) { | |||
| 146 | static void *tryagain (lua_State *L, void *block, | 146 | static void *tryagain (lua_State *L, void *block, |
| 147 | size_t osize, size_t nsize) { | 147 | size_t osize, size_t nsize) { |
| 148 | global_State *g = G(L); | 148 | global_State *g = G(L); |
| 149 | if (ttisnil(&g->nilvalue)) { /* is state fully build? */ | 149 | if (completestate(g)) { /* is state fully build? */ |
| 150 | luaC_fullgc(L, 1); /* try to free some memory... */ | 150 | luaC_fullgc(L, 1); /* try to free some memory... */ |
| 151 | return (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ | 151 | return (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ |
| 152 | } | 152 | } |
| @@ -226,8 +226,6 @@ static void init_registry (lua_State *L, global_State *g) { | |||
| 226 | 226 | ||
| 227 | /* | 227 | /* |
| 228 | ** open parts of the state that may cause memory-allocation errors. | 228 | ** open parts of the state that may cause memory-allocation errors. |
| 229 | ** ('g->nilvalue' being a nil value flags that the state was completely | ||
| 230 | ** build.) | ||
| 231 | */ | 229 | */ |
| 232 | static void f_luaopen (lua_State *L, void *ud) { | 230 | static void f_luaopen (lua_State *L, void *ud) { |
| 233 | global_State *g = G(L); | 231 | global_State *g = G(L); |
| @@ -238,7 +236,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
| 238 | luaT_init(L); | 236 | luaT_init(L); |
| 239 | luaX_init(L); | 237 | luaX_init(L); |
| 240 | g->gcrunning = 1; /* allow gc */ | 238 | g->gcrunning = 1; /* allow gc */ |
| 241 | setnilvalue(&g->nilvalue); | 239 | setnilvalue(&g->nilvalue); /* now state is complete */ |
| 242 | luai_userstateopen(L); | 240 | luai_userstateopen(L); |
| 243 | } | 241 | } |
| 244 | 242 | ||
| @@ -272,7 +270,7 @@ static void close_state (lua_State *L) { | |||
| 272 | global_State *g = G(L); | 270 | global_State *g = G(L); |
| 273 | luaD_closeprotected(L, 0, LUA_OK); /* close all upvalues */ | 271 | luaD_closeprotected(L, 0, LUA_OK); /* close all upvalues */ |
| 274 | luaC_freeallobjects(L); /* collect all objects */ | 272 | luaC_freeallobjects(L); /* collect all objects */ |
| 275 | if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ | 273 | if (completestate(g)) /* closing a fully built state? */ |
| 276 | luai_userstateclose(L); | 274 | luai_userstateclose(L); |
| 277 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); | 275 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); |
| 278 | freestack(L); | 276 | freestack(L); |
| @@ -324,6 +324,12 @@ struct lua_State { | |||
| 324 | 324 | ||
| 325 | #define G(L) (L->l_G) | 325 | #define G(L) (L->l_G) |
| 326 | 326 | ||
| 327 | /* | ||
| 328 | ** 'g->nilvalue' being a nil value flags that the state was completely | ||
| 329 | ** build. | ||
| 330 | */ | ||
| 331 | #define completestate(g) ttisnil(&g->nilvalue) | ||
| 332 | |||
| 327 | 333 | ||
| 328 | /* | 334 | /* |
| 329 | ** Union of all collectable objects (only for conversions) | 335 | ** Union of all collectable objects (only for conversions) |
