mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
Update EGC to r6 from r4
This commit is contained in:
parent
c9c4311f15
commit
6d26eed80f
@ -706,6 +706,9 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
||||
if (L != NULL && (mode & EGC_ALWAYS)) /* always collect memory if requested */
|
||||
luaC_fullgc(L);
|
||||
if(nsize > osize && L != NULL) {
|
||||
#if defined(LUA_STRESS_EMERGENCY_GC)
|
||||
luaC_fullgc(L);
|
||||
#endif
|
||||
if(G(L)->memlimit > 0 && (mode & EGC_ON_MEM_LIMIT) && l_check_memlimit(L, nsize - osize))
|
||||
return NULL;
|
||||
}
|
||||
|
@ -556,6 +556,15 @@ static void atomic (lua_State *L) {
|
||||
g->estimate = g->totalbytes - udsize; /* first estimate */
|
||||
}
|
||||
|
||||
static void sweepstrstep (global_State *g, lua_State *L) {
|
||||
lu_mem old = g->totalbytes;
|
||||
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
|
||||
if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */
|
||||
g->gcstate = GCSsweep; /* end sweep-string phase */
|
||||
lua_assert(old >= g->totalbytes);
|
||||
g->estimate -= old - g->totalbytes;
|
||||
}
|
||||
|
||||
|
||||
static l_mem singlestep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
@ -574,12 +583,7 @@ static l_mem singlestep (lua_State *L) {
|
||||
}
|
||||
}
|
||||
case GCSsweepstring: {
|
||||
lu_mem old = g->totalbytes;
|
||||
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
|
||||
if (g->sweepstrgc >= g->strt.size) /* nothing more to sweep? */
|
||||
g->gcstate = GCSsweep; /* end sweep-string phase */
|
||||
lua_assert(old >= g->totalbytes);
|
||||
g->estimate -= old - g->totalbytes;
|
||||
sweepstrstep(g, L);
|
||||
return GCSWEEPCOST;
|
||||
}
|
||||
case GCSsweep: {
|
||||
@ -641,6 +645,14 @@ void luaC_step (lua_State *L) {
|
||||
unset_block_gc(L);
|
||||
}
|
||||
|
||||
int luaC_sweepstrgc (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
if (g->gcstate == GCSsweepstring) {
|
||||
sweepstrstep(g, L);
|
||||
return (g->gcstate == GCSsweepstring) ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void luaC_fullgc (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
|
@ -123,6 +123,7 @@ LUAI_FUNC void luaC_callGCTM (lua_State *L);
|
||||
LUAI_FUNC void luaC_freeall (lua_State *L);
|
||||
LUAI_FUNC void luaC_step (lua_State *L);
|
||||
LUAI_FUNC void luaC_fullgc (lua_State *L);
|
||||
LUAI_FUNC int luaC_sweepstrgc (lua_State *L);
|
||||
LUAI_FUNC void luaC_marknew (lua_State *L, GCObject *o);
|
||||
LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
|
||||
LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
|
||||
|
@ -385,14 +385,18 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
|
||||
struct LexState lexstate;
|
||||
struct FuncState *pfuncstate = (struct FuncState*)malloc(sizeof(struct FuncState));
|
||||
Proto *res;
|
||||
TString *tname = luaS_new(L, name);
|
||||
setsvalue2s(L, L->top, tname); /* protect name */
|
||||
incr_top(L);
|
||||
lexstate.buff = buff;
|
||||
luaX_setinput(L, &lexstate, z, luaS_new(L, name));
|
||||
luaX_setinput(L, &lexstate, z, tname);
|
||||
open_func(&lexstate, pfuncstate);
|
||||
pfuncstate->f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */
|
||||
luaX_next(&lexstate); /* read first token */
|
||||
chunk(&lexstate);
|
||||
check(&lexstate, TK_EOS);
|
||||
close_func(&lexstate);
|
||||
L->top--; /* remove 'name' from stack */
|
||||
lua_assert(pfuncstate->prev == NULL);
|
||||
lua_assert(pfuncstate->f->nups == 0);
|
||||
lua_assert(lexstate.fs == NULL);
|
||||
|
@ -23,7 +23,7 @@ void luaS_resize (lua_State *L, int newsize) {
|
||||
stringtable *tb;
|
||||
int i;
|
||||
tb = &G(L)->strt;
|
||||
if (G(L)->gcstate == GCSsweepstring || newsize == tb->size || is_resizing_strings_gc(L))
|
||||
if (luaC_sweepstrgc(L) || newsize == tb->size || is_resizing_strings_gc(L))
|
||||
return; /* cannot resize during GC traverse or doesn't need to be resized */
|
||||
set_resizing_strings_gc(L);
|
||||
if (newsize > tb->size) {
|
||||
|
@ -408,7 +408,13 @@
|
||||
*/
|
||||
#define LUA_COMPAT_OPENLIB
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_STRESS_EMERGENCY_GC enables stress testing code for the Emergency GC.
|
||||
** CHANGE it to defined if you want to test for Emergency GC related bugs.
|
||||
** Note that this will make the Lua vm very slow, since it will force a
|
||||
** full GC on every new allocation.
|
||||
*/
|
||||
#undef LUA_STRESS_EMERGENCY_GC
|
||||
|
||||
/*
|
||||
@@ luai_apicheck is the assert macro used by the Lua-C API.
|
||||
|
Loading…
x
Reference in New Issue
Block a user