Fix 32/64 bit portability issue with upval->v.

This commit is contained in:
Mike Pall 2010-01-09 21:11:35 +01:00
parent ece20f8ca2
commit a33204ae5e
7 changed files with 21 additions and 22 deletions

View File

@ -812,7 +812,7 @@ static const char *aux_upvalue(cTValue *f, uint32_t idx, TValue **val)
if (isluafunc(fn)) {
GCproto *pt = funcproto(fn);
if (idx < pt->sizeuvname) {
*val = gcref(fn->l.uvptr[idx])->uv.v;
*val = uvval(&gcref(fn->l.uvptr[idx])->uv);
return strdata(pt->uvname[idx]);
}
} else {

View File

@ -1702,7 +1702,7 @@ static void asm_uref(ASMState *as, IRIns *ir)
Reg dest = ra_dest(as, ir, RSET_GPR);
if (irref_isk(ir->op1)) {
GCfunc *fn = ir_kfunc(IR(ir->op1));
TValue **v = &gcref(fn->l.uvptr[ir->op2])->uv.v;
MRef *v = &gcref(fn->l.uvptr[ir->op2])->uv.v;
emit_rma(as, XO_MOV, dest, v);
} else {
Reg uv = ra_scratch(as, RSET_GPR);

View File

@ -76,9 +76,9 @@ static GCupval *func_finduv(lua_State *L, TValue *slot)
GCupval *p;
GCupval *uv;
/* Search the sorted list of open upvalues. */
while (gcref(*pp) != NULL && (p = gco2uv(gcref(*pp)))->v >= slot) {
lua_assert(!p->closed && p->v != &p->tv);
if (p->v == slot) { /* Found open upvalue pointing to same slot? */
while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) {
lua_assert(!p->closed && uvval(p) != &p->tv);
if (uvval(p) == slot) { /* Found open upvalue pointing to same slot? */
if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */
flipwhite(obj2gco(p));
return p;
@ -90,7 +90,7 @@ static GCupval *func_finduv(lua_State *L, TValue *slot)
newwhite(g, uv);
uv->gct = ~LJ_TUPVAL;
uv->closed = 0; /* Still open. */
uv->v = slot; /* Pointing to the stack slot. */
setmref(uv->v, slot); /* Pointing to the stack slot. */
/* NOBARRIER: The GCupval is new (marked white) and open. */
setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */
setgcref(*pp, obj2gco(uv));
@ -108,9 +108,9 @@ void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level)
GCupval *uv;
global_State *g = G(L);
while (gcref(L->openupval) != NULL &&
(uv = gco2uv(gcref(L->openupval)))->v >= level) {
uvval((uv = gco2uv(gcref(L->openupval)))) >= level) {
GCobj *o = obj2gco(uv);
lua_assert(!isblack(o) && !uv->closed && uv->v != &uv->tv);
lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv);
setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */
if (isdead(g, o)) {
lj_func_freeuv(g, uv);

View File

@ -62,7 +62,7 @@ static void gc_mark(global_State *g, GCobj *o)
gc_markobj(g, tabref(gco2ud(o)->env));
} else if (LJ_UNLIKELY(o->gch.gct == ~LJ_TUPVAL)) {
GCupval *uv = gco2uv(o);
gc_marktv(g, uv->v);
gc_marktv(g, uvval(uv));
if (uv->closed)
gray2black(o); /* Closed upvalues are never gray. */
} else if (o->gch.gct != ~LJ_TSTR) {
@ -102,7 +102,7 @@ static void gc_mark_uv(global_State *g)
for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {
lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
if (isgray(obj2gco(uv)))
gc_marktv(g, uv->v);
gc_marktv(g, uvval(uv));
}
}
@ -727,16 +727,16 @@ void lj_gc_closeuv(global_State *g, GCupval *uv)
{
GCobj *o = obj2gco(uv);
/* Copy stack slot to upvalue itself and point to the copy. */
copyTV(mainthread(g), &uv->tv, uv->v);
uv->v = &uv->tv;
copyTV(mainthread(g), &uv->tv, uvval(uv));
setmref(uv->v, &uv->tv);
uv->closed = 1;
setgcrefr(o->gch.nextgc, g->gc.root);
setgcref(g->gc.root, o);
if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */
if (g->gc.state == GCSpropagate) {
gray2black(o); /* Make it black and preserve invariant. */
if (tviswhite(uv->v))
lj_gc_barrierf(g, o, gcV(uv->v));
if (tviswhite(&uv->tv))
lj_gc_barrierf(g, o, gcV(&uv->tv));
} else {
makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */
lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);

View File

@ -396,14 +396,13 @@ typedef struct GCupval {
GCRef next;
};
};
TValue *v; /* Points to stack slot (open) or above (closed). */
#if LJ_32
int32_t unusedv; /* For consistent alignment (32 bit only). */
#endif
MRef v; /* Points to stack slot (open) or above (closed). */
int32_t unusedv; /* For consistent alignment. */
} GCupval;
#define uvprev(uv_) (&gcref((uv_)->prev)->uv)
#define uvnext(uv_) (&gcref((uv_)->next)->uv)
#define uvval(uv_) (mref((uv_)->v, TValue))
/* -- Function object (closures) ------------------------------------------ */

View File

@ -790,8 +790,8 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
int needbarrier = 0;
if (!uvp->closed) {
/* In current stack? */
if (uvp->v >= J->L->stack && uvp->v < J->L->maxstack) {
int32_t slot = (int32_t)(uvp->v - (J->L->base - J->baseslot));
if (uvval(uvp) >= J->L->stack && uvval(uvp) < J->L->maxstack) {
int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));
if (slot >= 0) { /* Aliases an SSA slot? */
slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */
/* NYI: add IR to guard that it's still aliasing the same slot. */
@ -810,7 +810,7 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_PTR), fn, uv));
}
if (val == 0) { /* Upvalue load */
IRType t = itype2irt(uvp->v);
IRType t = itype2irt(uvval(uvp));
TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0);
if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */
return res;

View File

@ -61,7 +61,7 @@ static void resizestack(lua_State *L, MSize n)
L->base = (TValue *)((char *)L->base + delta);
L->top = (TValue *)((char *)L->top + delta);
for (up = gcref(L->openupval); up != NULL; up = gcnext(up))
gco2uv(up)->v = (TValue *)((char *)gco2uv(up)->v + delta);
setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta));
if (obj2gco(L) == gcref(G(L)->jit_L))
setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta);
}