2009-05-21 19:01:41 +00:00
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** $Id: lgc.c,v 2.38.1.1 2007/12/27 13:02:25 roberto Exp $
|
2009-05-21 19:01:41 +00:00
|
|
|
** Garbage Collector
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define lgc_c
|
|
|
|
#define LUA_CORE
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
#include "ldebug.h"
|
|
|
|
#include "ldo.h"
|
|
|
|
#include "lfunc.h"
|
|
|
|
#include "lgc.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "lstate.h"
|
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltable.h"
|
|
|
|
#include "ltm.h"
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define GCSTEPSIZE 1024u
|
|
|
|
#define GCSWEEPMAX 40
|
|
|
|
#define GCSWEEPCOST 10
|
|
|
|
#define GCFINALIZECOST 100
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define maskmarks cast_byte(~(bitmask(BLACKBIT)|WHITEBITS))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
#define makewhite(g,x) \
|
2014-04-02 18:46:06 +00:00
|
|
|
((x)->gch.marked = cast_byte(((x)->gch.marked & maskmarks) | luaC_white(g)))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
|
|
|
|
#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT)
|
|
|
|
#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define KEYWEAK bitmask(KEYWEAKBIT)
|
|
|
|
#define VALUEWEAK bitmask(VALUEWEAKBIT)
|
|
|
|
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
#define markvalue(g,o) { checkconsistency(o); \
|
2014-04-02 18:46:06 +00:00
|
|
|
if (iscollectable(o) && iswhite(gcvalue(o))) reallymarkobject(g,gcvalue(o)); }
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define markobject(g,t) { if (iswhite(obj2gco(t))) \
|
2009-05-21 19:01:41 +00:00
|
|
|
reallymarkobject(g, obj2gco(t)); }
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define setthreshold(g) (g->GCthreshold = (g->estimate/100) * g->gcpause)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void removeentry (Node *n) {
|
|
|
|
lua_assert(ttisnil(gval(n)));
|
2014-04-02 18:46:06 +00:00
|
|
|
if (iscollectable(gkey(n)))
|
|
|
|
setttype(gkey(n), LUA_TDEADKEY); /* dead key; remove it */
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void reallymarkobject (global_State *g, GCObject *o) {
|
2014-04-02 18:46:06 +00:00
|
|
|
lua_assert(iswhite(o) && !isdead(g, o));
|
2009-05-21 19:01:41 +00:00
|
|
|
white2gray(o);
|
2014-04-02 18:46:06 +00:00
|
|
|
switch (o->gch.tt) {
|
|
|
|
case LUA_TSTRING: {
|
|
|
|
return;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TUSERDATA: {
|
|
|
|
Table *mt = gco2u(o)->metatable;
|
2014-04-02 18:46:06 +00:00
|
|
|
gray2black(o); /* udata are never gray */
|
|
|
|
if (mt) markobject(g, mt);
|
2009-05-21 19:01:41 +00:00
|
|
|
markobject(g, gco2u(o)->env);
|
2014-04-02 18:46:06 +00:00
|
|
|
return;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TUPVAL: {
|
|
|
|
UpVal *uv = gco2uv(o);
|
|
|
|
markvalue(g, uv->v);
|
2014-04-02 18:46:06 +00:00
|
|
|
if (uv->v == &uv->u.value) /* closed? */
|
|
|
|
gray2black(o); /* open upvalues are never black */
|
2009-05-21 19:01:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
case LUA_TFUNCTION: {
|
|
|
|
gco2cl(o)->c.gclist = g->gray;
|
2009-05-21 19:01:41 +00:00
|
|
|
g->gray = o;
|
2014-04-02 18:46:06 +00:00
|
|
|
break;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TTABLE: {
|
2014-04-02 18:46:06 +00:00
|
|
|
gco2h(o)->gclist = g->gray;
|
|
|
|
g->gray = o;
|
|
|
|
break;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TTHREAD: {
|
|
|
|
gco2th(o)->gclist = g->gray;
|
|
|
|
g->gray = o;
|
2014-04-02 18:46:06 +00:00
|
|
|
break;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TPROTO: {
|
|
|
|
gco2p(o)->gclist = g->gray;
|
|
|
|
g->gray = o;
|
2014-04-02 18:46:06 +00:00
|
|
|
break;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
default: lua_assert(0);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void marktmu (global_State *g) {
|
|
|
|
GCObject *u = g->tmudata;
|
|
|
|
if (u) {
|
|
|
|
do {
|
|
|
|
u = u->gch.next;
|
|
|
|
makewhite(g, u); /* may be marked, if left from previous GC */
|
|
|
|
reallymarkobject(g, u);
|
|
|
|
} while (u != g->tmudata);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* move `dead' udata that need finalization to list `tmudata' */
|
|
|
|
size_t luaC_separateudata (lua_State *L, int all) {
|
|
|
|
global_State *g = G(L);
|
|
|
|
size_t deadmem = 0;
|
|
|
|
GCObject **p = &g->mainthread->next;
|
|
|
|
GCObject *curr;
|
|
|
|
while ((curr = *p) != NULL) {
|
|
|
|
if (!(iswhite(curr) || all) || isfinalized(gco2u(curr)))
|
|
|
|
p = &curr->gch.next; /* don't bother with them */
|
|
|
|
else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {
|
|
|
|
markfinalized(gco2u(curr)); /* don't need finalization */
|
|
|
|
p = &curr->gch.next;
|
|
|
|
}
|
|
|
|
else { /* must call its gc method */
|
|
|
|
deadmem += sizeudata(gco2u(curr));
|
|
|
|
markfinalized(gco2u(curr));
|
|
|
|
*p = curr->gch.next;
|
|
|
|
/* link `curr' at the end of `tmudata' list */
|
|
|
|
if (g->tmudata == NULL) /* list is empty? */
|
|
|
|
g->tmudata = curr->gch.next = curr; /* creates a circular list */
|
|
|
|
else {
|
|
|
|
curr->gch.next = g->tmudata->gch.next;
|
|
|
|
g->tmudata->gch.next = curr;
|
|
|
|
g->tmudata = curr;
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
return deadmem;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static int traversetable (global_State *g, Table *h) {
|
|
|
|
int i;
|
|
|
|
int weakkey = 0;
|
|
|
|
int weakvalue = 0;
|
|
|
|
const TValue *mode;
|
|
|
|
if (h->metatable)
|
|
|
|
markobject(g, h->metatable);
|
|
|
|
mode = gfasttm(g, h->metatable, TM_MODE);
|
|
|
|
if (mode && ttisstring(mode)) { /* is there a weak mode? */
|
|
|
|
weakkey = (strchr(svalue(mode), 'k') != NULL);
|
|
|
|
weakvalue = (strchr(svalue(mode), 'v') != NULL);
|
|
|
|
if (weakkey || weakvalue) { /* is really weak? */
|
|
|
|
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
|
|
|
|
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |
|
|
|
|
(weakvalue << VALUEWEAKBIT));
|
|
|
|
h->gclist = g->weak; /* must be cleared after GC, ... */
|
|
|
|
g->weak = obj2gco(h); /* ... so put in the appropriate list */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (weakkey && weakvalue) return 1;
|
|
|
|
if (!weakvalue) {
|
|
|
|
i = h->sizearray;
|
|
|
|
while (i--)
|
|
|
|
markvalue(g, &h->array[i]);
|
|
|
|
}
|
|
|
|
i = sizenode(h);
|
|
|
|
while (i--) {
|
|
|
|
Node *n = gnode(h, i);
|
|
|
|
lua_assert(ttype(gkey(n)) != LUA_TDEADKEY || ttisnil(gval(n)));
|
|
|
|
if (ttisnil(gval(n)))
|
|
|
|
removeentry(n); /* remove empty entries */
|
2009-05-21 19:01:41 +00:00
|
|
|
else {
|
|
|
|
lua_assert(!ttisnil(gkey(n)));
|
2014-04-02 18:46:06 +00:00
|
|
|
if (!weakkey) markvalue(g, gkey(n));
|
|
|
|
if (!weakvalue) markvalue(g, gval(n));
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
return weakkey || weakvalue;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/*
|
|
|
|
** All marks are conditional because a GC may happen while the
|
|
|
|
** prototype is still being created
|
|
|
|
*/
|
|
|
|
static void traverseproto (global_State *g, Proto *f) {
|
2009-05-21 19:01:41 +00:00
|
|
|
int i;
|
2014-04-02 18:46:06 +00:00
|
|
|
if (f->source) stringmark(f->source);
|
|
|
|
for (i=0; i<f->sizek; i++) /* mark literals */
|
|
|
|
markvalue(g, &f->k[i]);
|
|
|
|
for (i=0; i<f->sizeupvalues; i++) { /* mark upvalue names */
|
|
|
|
if (f->upvalues[i])
|
|
|
|
stringmark(f->upvalues[i]);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
for (i=0; i<f->sizep; i++) { /* mark nested protos */
|
|
|
|
if (f->p[i])
|
|
|
|
markobject(g, f->p[i]);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
for (i=0; i<f->sizelocvars; i++) { /* mark local-variable names */
|
|
|
|
if (f->locvars[i].varname)
|
|
|
|
stringmark(f->locvars[i].varname);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void traverseclosure (global_State *g, Closure *cl) {
|
|
|
|
markobject(g, cl->c.env);
|
|
|
|
if (cl->c.isC) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */
|
|
|
|
markvalue(g, &cl->c.upvalue[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
lua_assert(cl->l.nupvalues == cl->l.p->nups);
|
|
|
|
markobject(g, cl->l.p);
|
|
|
|
for (i=0; i<cl->l.nupvalues; i++) /* mark its upvalues */
|
|
|
|
markobject(g, cl->l.upvals[i]);
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void checkstacksizes (lua_State *L, StkId max) {
|
|
|
|
int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
|
|
|
|
int s_used = cast_int(max - L->stack); /* part of stack in use */
|
|
|
|
if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
|
|
|
|
return; /* do not touch the stacks */
|
|
|
|
if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
|
|
|
|
luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
|
|
|
|
condhardstacktests(luaD_reallocCI(L, ci_used + 1));
|
|
|
|
if (4*s_used < L->stacksize &&
|
|
|
|
2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
|
|
|
|
luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
|
|
|
|
condhardstacktests(luaD_reallocstack(L, s_used));
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void traversestack (global_State *g, lua_State *l) {
|
|
|
|
StkId o, lim;
|
|
|
|
CallInfo *ci;
|
|
|
|
markvalue(g, gt(l));
|
|
|
|
lim = l->top;
|
|
|
|
for (ci = l->base_ci; ci <= l->ci; ci++) {
|
|
|
|
lua_assert(ci->top <= l->stack_last);
|
|
|
|
if (lim < ci->top) lim = ci->top;
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
for (o = l->stack; o < l->top; o++)
|
|
|
|
markvalue(g, o);
|
|
|
|
for (; o <= lim; o++)
|
|
|
|
setnilvalue(o);
|
|
|
|
checkstacksizes(l, lim);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** traverse one gray object, turning it to black.
|
|
|
|
** Returns `quantity' traversed.
|
2009-05-21 19:01:41 +00:00
|
|
|
*/
|
2014-04-02 18:46:06 +00:00
|
|
|
static l_mem propagatemark (global_State *g) {
|
2009-05-21 19:01:41 +00:00
|
|
|
GCObject *o = g->gray;
|
|
|
|
lua_assert(isgray(o));
|
|
|
|
gray2black(o);
|
2014-04-02 18:46:06 +00:00
|
|
|
switch (o->gch.tt) {
|
2009-05-21 19:01:41 +00:00
|
|
|
case LUA_TTABLE: {
|
2014-04-02 18:46:06 +00:00
|
|
|
Table *h = gco2h(o);
|
|
|
|
g->gray = h->gclist;
|
|
|
|
if (traversetable(g, h)) /* table is weak? */
|
|
|
|
black2gray(o); /* keep it gray */
|
|
|
|
return sizeof(Table) + sizeof(TValue) * h->sizearray +
|
|
|
|
sizeof(Node) * sizenode(h);
|
|
|
|
}
|
|
|
|
case LUA_TFUNCTION: {
|
|
|
|
Closure *cl = gco2cl(o);
|
|
|
|
g->gray = cl->c.gclist;
|
|
|
|
traverseclosure(g, cl);
|
|
|
|
return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
|
|
|
|
sizeLclosure(cl->l.nupvalues);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TTHREAD: {
|
|
|
|
lua_State *th = gco2th(o);
|
2014-04-02 18:46:06 +00:00
|
|
|
g->gray = th->gclist;
|
2009-05-21 19:01:41 +00:00
|
|
|
th->gclist = g->grayagain;
|
2014-04-02 18:46:06 +00:00
|
|
|
g->grayagain = o;
|
2009-05-21 19:01:41 +00:00
|
|
|
black2gray(o);
|
2014-04-02 18:46:06 +00:00
|
|
|
traversestack(g, th);
|
|
|
|
return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
|
|
|
|
sizeof(CallInfo) * th->size_ci;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case LUA_TPROTO: {
|
|
|
|
Proto *p = gco2p(o);
|
2014-04-02 18:46:06 +00:00
|
|
|
g->gray = p->gclist;
|
|
|
|
traverseproto(g, p);
|
|
|
|
return sizeof(Proto) + sizeof(Instruction) * p->sizecode +
|
|
|
|
sizeof(Proto *) * p->sizep +
|
|
|
|
sizeof(TValue) * p->sizek +
|
|
|
|
sizeof(int) * p->sizelineinfo +
|
|
|
|
sizeof(LocVar) * p->sizelocvars +
|
|
|
|
sizeof(TString *) * p->sizeupvalues;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
default: lua_assert(0); return 0;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static size_t propagateall (global_State *g) {
|
|
|
|
size_t m = 0;
|
|
|
|
while (g->gray) m += propagatemark(g);
|
|
|
|
return m;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** The next function tells whether a key or value can be cleared from
|
|
|
|
** a weak table. Non-collectable objects are never removed from weak
|
|
|
|
** tables. Strings behave as `values', so are never removed too. for
|
|
|
|
** other objects: if really collected, cannot keep them; for userdata
|
|
|
|
** being finalized, keep them in keys, but not in values
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
*/
|
2014-04-02 18:46:06 +00:00
|
|
|
static int iscleared (const TValue *o, int iskey) {
|
|
|
|
if (!iscollectable(o)) return 0;
|
|
|
|
if (ttisstring(o)) {
|
|
|
|
stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
|
|
|
|
return 0;
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
return iswhite(gcvalue(o)) ||
|
|
|
|
(ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** clear collected entries from weaktables
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
*/
|
2014-04-02 18:46:06 +00:00
|
|
|
static void cleartable (GCObject *l) {
|
|
|
|
while (l) {
|
|
|
|
Table *h = gco2h(l);
|
|
|
|
int i = h->sizearray;
|
|
|
|
lua_assert(testbit(h->marked, VALUEWEAKBIT) ||
|
|
|
|
testbit(h->marked, KEYWEAKBIT));
|
|
|
|
if (testbit(h->marked, VALUEWEAKBIT)) {
|
|
|
|
while (i--) {
|
|
|
|
TValue *o = &h->array[i];
|
|
|
|
if (iscleared(o, 0)) /* value was collected? */
|
|
|
|
setnilvalue(o); /* remove value */
|
|
|
|
}
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
i = sizenode(h);
|
|
|
|
while (i--) {
|
|
|
|
Node *n = gnode(h, i);
|
|
|
|
if (!ttisnil(gval(n)) && /* non-empty entry? */
|
|
|
|
(iscleared(key2tval(n), 1) || iscleared(gval(n), 0))) {
|
2009-05-21 19:01:41 +00:00
|
|
|
setnilvalue(gval(n)); /* remove value ... */
|
2014-04-02 18:46:06 +00:00
|
|
|
removeentry(n); /* remove entry from table */
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
l = h->gclist;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void freeobj (lua_State *L, GCObject *o) {
|
2014-04-02 18:46:06 +00:00
|
|
|
switch (o->gch.tt) {
|
2009-05-21 19:01:41 +00:00
|
|
|
case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
|
2014-04-02 18:46:06 +00:00
|
|
|
case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
|
|
|
|
case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
|
|
|
|
case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
|
|
|
|
case LUA_TTHREAD: {
|
|
|
|
lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);
|
|
|
|
luaE_freethread(L, gco2th(o));
|
2009-05-21 19:01:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
case LUA_TSTRING: {
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
G(L)->strt.nuse--;
|
|
|
|
luaM_freemem(L, o, sizestring(gco2ts(o)));
|
2009-05-21 19:01:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
case LUA_TUSERDATA: {
|
|
|
|
luaM_freemem(L, o, sizeudata(gco2u(o)));
|
|
|
|
break;
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
default: lua_assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define sweepwholelist(L,p) sweeplist(L,p,MAX_LUMEM)
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
|
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *curr;
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
int deadmask = otherwhite(g);
|
|
|
|
while ((curr = *p) != NULL && count-- > 0) {
|
|
|
|
if (curr->gch.tt == LUA_TTHREAD) /* sweep open upvalues of each thread */
|
|
|
|
sweepwholelist(L, &gco2th(curr)->openupval);
|
|
|
|
if ((curr->gch.marked ^ WHITEBITS) & deadmask) { /* not dead? */
|
|
|
|
lua_assert(!isdead(g, curr) || testbit(curr->gch.marked, FIXEDBIT));
|
|
|
|
makewhite(g, curr); /* make it white (for next cycle) */
|
|
|
|
p = &curr->gch.next;
|
|
|
|
}
|
|
|
|
else { /* must erase `curr' */
|
|
|
|
lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT));
|
|
|
|
*p = curr->gch.next;
|
|
|
|
if (curr == g->rootgc) /* is the first element of the list? */
|
|
|
|
g->rootgc = curr->gch.next; /* adjust first */
|
|
|
|
freeobj(L, curr);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void checkSizes (lua_State *L) {
|
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
/* check size of string hash */
|
|
|
|
if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&
|
|
|
|
g->strt.size > MINSTRTABSIZE*2)
|
|
|
|
luaS_resize(L, g->strt.size/2); /* table is too big */
|
|
|
|
/* check size of buffer */
|
|
|
|
if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */
|
|
|
|
size_t newsize = luaZ_sizebuffer(&g->buff) / 2;
|
|
|
|
luaZ_resizebuffer(L, &g->buff, newsize);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void GCTM (lua_State *L) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *o = g->tmudata->gch.next; /* get first element */
|
|
|
|
Udata *udata = rawgco2u(o);
|
2009-05-21 19:01:41 +00:00
|
|
|
const TValue *tm;
|
2014-04-02 18:46:06 +00:00
|
|
|
/* remove udata from `tmudata' */
|
|
|
|
if (o == g->tmudata) /* last element? */
|
|
|
|
g->tmudata = NULL;
|
|
|
|
else
|
|
|
|
g->tmudata->gch.next = udata->uv.next;
|
|
|
|
udata->uv.next = g->mainthread->next; /* return it to `root' list */
|
|
|
|
g->mainthread->next = o;
|
|
|
|
makewhite(g, o);
|
|
|
|
tm = fasttm(L, udata->uv.metatable, TM_GC);
|
|
|
|
if (tm != NULL) {
|
2009-05-21 19:01:41 +00:00
|
|
|
lu_byte oldah = L->allowhook;
|
2014-04-02 18:46:06 +00:00
|
|
|
lu_mem oldt = g->GCthreshold;
|
|
|
|
L->allowhook = 0; /* stop debug hooks during GC tag method */
|
|
|
|
g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */
|
|
|
|
setobj2s(L, L->top, tm);
|
|
|
|
setuvalue(L, L->top+1, udata);
|
|
|
|
L->top += 2;
|
|
|
|
luaD_call(L, L->top - 2, 0);
|
2009-05-21 19:01:41 +00:00
|
|
|
L->allowhook = oldah; /* restore hooks */
|
2014-04-02 18:46:06 +00:00
|
|
|
g->GCthreshold = oldt; /* restore threshold */
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** Call all GC tag methods
|
2009-05-21 19:01:41 +00:00
|
|
|
*/
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_callGCTM (lua_State *L) {
|
|
|
|
while (G(L)->tmudata)
|
|
|
|
GCTM(L);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_freeall (lua_State *L) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
int i;
|
|
|
|
g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* mask to collect all elements */
|
|
|
|
sweepwholelist(L, &g->rootgc);
|
|
|
|
for (i = 0; i < g->strt.size; i++) /* free all string lists */
|
|
|
|
sweepwholelist(L, &g->strt.hash[i]);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void markmt (global_State *g) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<NUM_TAGS; i++)
|
|
|
|
if (g->mt[i]) markobject(g, g->mt[i]);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* mark root set */
|
|
|
|
static void markroot (lua_State *L) {
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
g->gray = NULL;
|
|
|
|
g->grayagain = NULL;
|
|
|
|
g->weak = NULL;
|
|
|
|
markobject(g, g->mainthread);
|
|
|
|
/* make global table be traversed before main stack */
|
|
|
|
markvalue(g, gt(g->mainthread));
|
|
|
|
markvalue(g, registry(L));
|
|
|
|
markmt(g);
|
|
|
|
g->gcstate = GCSpropagate;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void remarkupvals (global_State *g) {
|
|
|
|
UpVal *uv;
|
|
|
|
for (uv = g->uvhead.u.l.next; uv != &g->uvhead; uv = uv->u.l.next) {
|
|
|
|
lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
|
|
|
|
if (isgray(obj2gco(uv)))
|
|
|
|
markvalue(g, uv->v);
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static void atomic (lua_State *L) {
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
size_t udsize; /* total size of userdata to be finalized */
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
/* remark occasional upvalues of (maybe) dead threads */
|
|
|
|
remarkupvals(g);
|
2014-04-02 18:46:06 +00:00
|
|
|
/* traverse objects cautch by write barrier and by 'remarkupvals' */
|
|
|
|
propagateall(g);
|
|
|
|
/* remark weak tables */
|
|
|
|
g->gray = g->weak;
|
|
|
|
g->weak = NULL;
|
|
|
|
lua_assert(!iswhite(obj2gco(g->mainthread)));
|
|
|
|
markobject(g, L); /* mark running thread */
|
|
|
|
markmt(g); /* mark basic metatables (again) */
|
|
|
|
propagateall(g);
|
|
|
|
/* remark gray again */
|
|
|
|
g->gray = g->grayagain;
|
|
|
|
g->grayagain = NULL;
|
|
|
|
propagateall(g);
|
|
|
|
udsize = luaC_separateudata(L, 0); /* separate userdata to be finalized */
|
|
|
|
marktmu(g); /* mark `preserved' userdata */
|
|
|
|
udsize += propagateall(g); /* remark, to propagate `preserveness' */
|
|
|
|
cleartable(g->weak); /* remove collected objects from weak tables */
|
|
|
|
/* flip current white */
|
|
|
|
g->currentwhite = cast_byte(otherwhite(g));
|
|
|
|
g->sweepstrgc = 0;
|
|
|
|
g->sweepgc = &g->rootgc;
|
|
|
|
g->gcstate = GCSsweepstring;
|
|
|
|
g->estimate = g->totalbytes - udsize; /* first estimate */
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
static l_mem singlestep (lua_State *L) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
/*lua_checkmemory(L);*/
|
2009-05-21 19:01:41 +00:00
|
|
|
switch (g->gcstate) {
|
|
|
|
case GCSpause: {
|
2014-04-02 18:46:06 +00:00
|
|
|
markroot(L); /* start a new collection */
|
|
|
|
return 0;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
case GCSpropagate: {
|
2014-04-02 18:46:06 +00:00
|
|
|
if (g->gray)
|
|
|
|
return propagatemark(g);
|
2009-05-21 19:01:41 +00:00
|
|
|
else { /* no more `gray' objects */
|
2014-04-02 18:46:06 +00:00
|
|
|
atomic(L); /* finish mark phase */
|
|
|
|
return 0;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case GCSsweepstring: {
|
2014-04-02 18:46:06 +00:00
|
|
|
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;
|
|
|
|
return GCSWEEPCOST;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
case GCSsweep: {
|
2014-04-02 18:46:06 +00:00
|
|
|
lu_mem old = g->totalbytes;
|
|
|
|
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
|
|
|
if (*g->sweepgc == NULL) { /* nothing more to sweep? */
|
|
|
|
checkSizes(L);
|
|
|
|
g->gcstate = GCSfinalize; /* end sweep phase */
|
|
|
|
}
|
|
|
|
lua_assert(old >= g->totalbytes);
|
|
|
|
g->estimate -= old - g->totalbytes;
|
|
|
|
return GCSWEEPMAX*GCSWEEPCOST;
|
|
|
|
}
|
|
|
|
case GCSfinalize: {
|
|
|
|
if (g->tmudata) {
|
|
|
|
GCTM(L);
|
|
|
|
if (g->estimate > GCFINALIZECOST)
|
|
|
|
g->estimate -= GCFINALIZECOST;
|
|
|
|
return GCFINALIZECOST;
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-02 18:46:06 +00:00
|
|
|
g->gcstate = GCSpause; /* end collection */
|
|
|
|
g->gcdept = 0;
|
|
|
|
return 0;
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
default: lua_assert(0); return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_step (lua_State *L) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
|
|
|
|
if (lim == 0)
|
|
|
|
lim = (MAX_LUMEM-1)/2; /* no limit */
|
|
|
|
g->gcdept += g->totalbytes - g->GCthreshold;
|
|
|
|
do {
|
|
|
|
lim -= singlestep(L);
|
|
|
|
if (g->gcstate == GCSpause)
|
|
|
|
break;
|
|
|
|
} while (lim > 0);
|
|
|
|
if (g->gcstate != GCSpause) {
|
|
|
|
if (g->gcdept < GCSTEPSIZE)
|
|
|
|
g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/g->gcstepmul;*/
|
|
|
|
else {
|
|
|
|
g->gcdept -= GCSTEPSIZE;
|
|
|
|
g->GCthreshold = g->totalbytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lua_assert(g->totalbytes >= g->estimate);
|
|
|
|
setthreshold(g);
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_fullgc (lua_State *L) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
if (g->gcstate <= GCSpropagate) {
|
|
|
|
/* reset sweep marks to sweep all elements (returning them to white) */
|
|
|
|
g->sweepstrgc = 0;
|
|
|
|
g->sweepgc = &g->rootgc;
|
|
|
|
/* reset other collector lists */
|
|
|
|
g->gray = NULL;
|
|
|
|
g->grayagain = NULL;
|
|
|
|
g->weak = NULL;
|
|
|
|
g->gcstate = GCSsweepstring;
|
|
|
|
}
|
|
|
|
lua_assert(g->gcstate != GCSpause && g->gcstate != GCSpropagate);
|
|
|
|
/* finish any pending sweep phase */
|
|
|
|
while (g->gcstate != GCSfinalize) {
|
|
|
|
lua_assert(g->gcstate == GCSsweepstring || g->gcstate == GCSsweep);
|
|
|
|
singlestep(L);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
markroot(L);
|
|
|
|
while (g->gcstate != GCSpause) {
|
|
|
|
singlestep(L);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
2014-04-02 18:46:06 +00:00
|
|
|
setthreshold(g);
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
|
|
|
|
lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
|
|
|
|
lua_assert(ttype(&o->gch) != LUA_TTABLE);
|
|
|
|
/* must keep invariant? */
|
|
|
|
if (g->gcstate == GCSpropagate)
|
|
|
|
reallymarkobject(g, v); /* restore invariant */
|
|
|
|
else /* don't mind */
|
|
|
|
makewhite(g, o); /* mark as white just to avoid other barriers */
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_barrierback (lua_State *L, Table *t) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *o = obj2gco(t);
|
|
|
|
lua_assert(isblack(o) && !isdead(g, o));
|
|
|
|
lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
|
|
|
|
black2gray(o); /* make table gray (again) */
|
|
|
|
t->gclist = g->grayagain;
|
|
|
|
g->grayagain = o;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_link (lua_State *L, GCObject *o, lu_byte tt) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
o->gch.next = g->rootgc;
|
|
|
|
g->rootgc = o;
|
|
|
|
o->gch.marked = luaC_white(g);
|
|
|
|
o->gch.tt = tt;
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
void luaC_linkupval (lua_State *L, UpVal *uv) {
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *g = G(L);
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *o = obj2gco(uv);
|
|
|
|
o->gch.next = g->rootgc; /* link upvalue into `rootgc' list */
|
|
|
|
g->rootgc = o;
|
|
|
|
if (isgray(o)) {
|
|
|
|
if (g->gcstate == GCSpropagate) {
|
|
|
|
gray2black(o); /* closed upvalues need barrier */
|
|
|
|
luaC_barrier(L, uv, uv->v);
|
|
|
|
}
|
|
|
|
else { /* sweep phase: sweep it (turning it into white) */
|
|
|
|
makewhite(g, o);
|
|
|
|
lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
|
|
|
|
}
|
2009-05-21 19:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|