aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-01-09 21:11:35 +0100
committerMike Pall <mike>2010-01-09 21:11:35 +0100
commita33204ae5eae25291f003c386ab993278194b96b (patch)
treec56a9e30ee74f455ae6d9cab8dd366f08946174b /src
parentece20f8ca28f16519a6d4b6a7fc0e5d3e668b314 (diff)
downloadluajit-a33204ae5eae25291f003c386ab993278194b96b.tar.gz
luajit-a33204ae5eae25291f003c386ab993278194b96b.tar.bz2
luajit-a33204ae5eae25291f003c386ab993278194b96b.zip
Fix 32/64 bit portability issue with upval->v.
Diffstat (limited to 'src')
-rw-r--r--src/lj_api.c2
-rw-r--r--src/lj_asm.c2
-rw-r--r--src/lj_func.c12
-rw-r--r--src/lj_gc.c12
-rw-r--r--src/lj_obj.h7
-rw-r--r--src/lj_record.c6
-rw-r--r--src/lj_state.c2
7 files changed, 21 insertions, 22 deletions
diff --git a/src/lj_api.c b/src/lj_api.c
index dbeb6af0..a2d29723 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -812,7 +812,7 @@ static const char *aux_upvalue(cTValue *f, uint32_t idx, TValue **val)
812 if (isluafunc(fn)) { 812 if (isluafunc(fn)) {
813 GCproto *pt = funcproto(fn); 813 GCproto *pt = funcproto(fn);
814 if (idx < pt->sizeuvname) { 814 if (idx < pt->sizeuvname) {
815 *val = gcref(fn->l.uvptr[idx])->uv.v; 815 *val = uvval(&gcref(fn->l.uvptr[idx])->uv);
816 return strdata(pt->uvname[idx]); 816 return strdata(pt->uvname[idx]);
817 } 817 }
818 } else { 818 } else {
diff --git a/src/lj_asm.c b/src/lj_asm.c
index 21bfa6db..50f877e7 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1702,7 +1702,7 @@ static void asm_uref(ASMState *as, IRIns *ir)
1702 Reg dest = ra_dest(as, ir, RSET_GPR); 1702 Reg dest = ra_dest(as, ir, RSET_GPR);
1703 if (irref_isk(ir->op1)) { 1703 if (irref_isk(ir->op1)) {
1704 GCfunc *fn = ir_kfunc(IR(ir->op1)); 1704 GCfunc *fn = ir_kfunc(IR(ir->op1));
1705 TValue **v = &gcref(fn->l.uvptr[ir->op2])->uv.v; 1705 MRef *v = &gcref(fn->l.uvptr[ir->op2])->uv.v;
1706 emit_rma(as, XO_MOV, dest, v); 1706 emit_rma(as, XO_MOV, dest, v);
1707 } else { 1707 } else {
1708 Reg uv = ra_scratch(as, RSET_GPR); 1708 Reg uv = ra_scratch(as, RSET_GPR);
diff --git a/src/lj_func.c b/src/lj_func.c
index b679ec81..abb7afd5 100644
--- a/src/lj_func.c
+++ b/src/lj_func.c
@@ -76,9 +76,9 @@ static GCupval *func_finduv(lua_State *L, TValue *slot)
76 GCupval *p; 76 GCupval *p;
77 GCupval *uv; 77 GCupval *uv;
78 /* Search the sorted list of open upvalues. */ 78 /* Search the sorted list of open upvalues. */
79 while (gcref(*pp) != NULL && (p = gco2uv(gcref(*pp)))->v >= slot) { 79 while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) {
80 lua_assert(!p->closed && p->v != &p->tv); 80 lua_assert(!p->closed && uvval(p) != &p->tv);
81 if (p->v == slot) { /* Found open upvalue pointing to same slot? */ 81 if (uvval(p) == slot) { /* Found open upvalue pointing to same slot? */
82 if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */ 82 if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */
83 flipwhite(obj2gco(p)); 83 flipwhite(obj2gco(p));
84 return p; 84 return p;
@@ -90,7 +90,7 @@ static GCupval *func_finduv(lua_State *L, TValue *slot)
90 newwhite(g, uv); 90 newwhite(g, uv);
91 uv->gct = ~LJ_TUPVAL; 91 uv->gct = ~LJ_TUPVAL;
92 uv->closed = 0; /* Still open. */ 92 uv->closed = 0; /* Still open. */
93 uv->v = slot; /* Pointing to the stack slot. */ 93 setmref(uv->v, slot); /* Pointing to the stack slot. */
94 /* NOBARRIER: The GCupval is new (marked white) and open. */ 94 /* NOBARRIER: The GCupval is new (marked white) and open. */
95 setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */ 95 setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */
96 setgcref(*pp, obj2gco(uv)); 96 setgcref(*pp, obj2gco(uv));
@@ -108,9 +108,9 @@ void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level)
108 GCupval *uv; 108 GCupval *uv;
109 global_State *g = G(L); 109 global_State *g = G(L);
110 while (gcref(L->openupval) != NULL && 110 while (gcref(L->openupval) != NULL &&
111 (uv = gco2uv(gcref(L->openupval)))->v >= level) { 111 uvval((uv = gco2uv(gcref(L->openupval)))) >= level) {
112 GCobj *o = obj2gco(uv); 112 GCobj *o = obj2gco(uv);
113 lua_assert(!isblack(o) && !uv->closed && uv->v != &uv->tv); 113 lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv);
114 setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */ 114 setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */
115 if (isdead(g, o)) { 115 if (isdead(g, o)) {
116 lj_func_freeuv(g, uv); 116 lj_func_freeuv(g, uv);
diff --git a/src/lj_gc.c b/src/lj_gc.c
index e3d02cd4..ffe5d4b1 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -62,7 +62,7 @@ static void gc_mark(global_State *g, GCobj *o)
62 gc_markobj(g, tabref(gco2ud(o)->env)); 62 gc_markobj(g, tabref(gco2ud(o)->env));
63 } else if (LJ_UNLIKELY(o->gch.gct == ~LJ_TUPVAL)) { 63 } else if (LJ_UNLIKELY(o->gch.gct == ~LJ_TUPVAL)) {
64 GCupval *uv = gco2uv(o); 64 GCupval *uv = gco2uv(o);
65 gc_marktv(g, uv->v); 65 gc_marktv(g, uvval(uv));
66 if (uv->closed) 66 if (uv->closed)
67 gray2black(o); /* Closed upvalues are never gray. */ 67 gray2black(o); /* Closed upvalues are never gray. */
68 } else if (o->gch.gct != ~LJ_TSTR) { 68 } else if (o->gch.gct != ~LJ_TSTR) {
@@ -102,7 +102,7 @@ static void gc_mark_uv(global_State *g)
102 for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) { 102 for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {
103 lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv); 103 lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
104 if (isgray(obj2gco(uv))) 104 if (isgray(obj2gco(uv)))
105 gc_marktv(g, uv->v); 105 gc_marktv(g, uvval(uv));
106 } 106 }
107} 107}
108 108
@@ -727,16 +727,16 @@ void lj_gc_closeuv(global_State *g, GCupval *uv)
727{ 727{
728 GCobj *o = obj2gco(uv); 728 GCobj *o = obj2gco(uv);
729 /* Copy stack slot to upvalue itself and point to the copy. */ 729 /* Copy stack slot to upvalue itself and point to the copy. */
730 copyTV(mainthread(g), &uv->tv, uv->v); 730 copyTV(mainthread(g), &uv->tv, uvval(uv));
731 uv->v = &uv->tv; 731 setmref(uv->v, &uv->tv);
732 uv->closed = 1; 732 uv->closed = 1;
733 setgcrefr(o->gch.nextgc, g->gc.root); 733 setgcrefr(o->gch.nextgc, g->gc.root);
734 setgcref(g->gc.root, o); 734 setgcref(g->gc.root, o);
735 if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */ 735 if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */
736 if (g->gc.state == GCSpropagate) { 736 if (g->gc.state == GCSpropagate) {
737 gray2black(o); /* Make it black and preserve invariant. */ 737 gray2black(o); /* Make it black and preserve invariant. */
738 if (tviswhite(uv->v)) 738 if (tviswhite(&uv->tv))
739 lj_gc_barrierf(g, o, gcV(uv->v)); 739 lj_gc_barrierf(g, o, gcV(&uv->tv));
740 } else { 740 } else {
741 makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */ 741 makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */
742 lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause); 742 lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
diff --git a/src/lj_obj.h b/src/lj_obj.h
index 12c02352..c237ebf5 100644
--- a/src/lj_obj.h
+++ b/src/lj_obj.h
@@ -396,14 +396,13 @@ typedef struct GCupval {
396 GCRef next; 396 GCRef next;
397 }; 397 };
398 }; 398 };
399 TValue *v; /* Points to stack slot (open) or above (closed). */ 399 MRef v; /* Points to stack slot (open) or above (closed). */
400#if LJ_32 400 int32_t unusedv; /* For consistent alignment. */
401 int32_t unusedv; /* For consistent alignment (32 bit only). */
402#endif
403} GCupval; 401} GCupval;
404 402
405#define uvprev(uv_) (&gcref((uv_)->prev)->uv) 403#define uvprev(uv_) (&gcref((uv_)->prev)->uv)
406#define uvnext(uv_) (&gcref((uv_)->next)->uv) 404#define uvnext(uv_) (&gcref((uv_)->next)->uv)
405#define uvval(uv_) (mref((uv_)->v, TValue))
407 406
408/* -- Function object (closures) ------------------------------------------ */ 407/* -- Function object (closures) ------------------------------------------ */
409 408
diff --git a/src/lj_record.c b/src/lj_record.c
index 02016b12..0dfd1f73 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -790,8 +790,8 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
790 int needbarrier = 0; 790 int needbarrier = 0;
791 if (!uvp->closed) { 791 if (!uvp->closed) {
792 /* In current stack? */ 792 /* In current stack? */
793 if (uvp->v >= J->L->stack && uvp->v < J->L->maxstack) { 793 if (uvval(uvp) >= J->L->stack && uvval(uvp) < J->L->maxstack) {
794 int32_t slot = (int32_t)(uvp->v - (J->L->base - J->baseslot)); 794 int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));
795 if (slot >= 0) { /* Aliases an SSA slot? */ 795 if (slot >= 0) { /* Aliases an SSA slot? */
796 slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */ 796 slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */
797 /* NYI: add IR to guard that it's still aliasing the same slot. */ 797 /* 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)
810 uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_PTR), fn, uv)); 810 uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_PTR), fn, uv));
811 } 811 }
812 if (val == 0) { /* Upvalue load */ 812 if (val == 0) { /* Upvalue load */
813 IRType t = itype2irt(uvp->v); 813 IRType t = itype2irt(uvval(uvp));
814 TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0); 814 TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0);
815 if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */ 815 if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */
816 return res; 816 return res;
diff --git a/src/lj_state.c b/src/lj_state.c
index 34da3690..e1b9021e 100644
--- a/src/lj_state.c
+++ b/src/lj_state.c
@@ -61,7 +61,7 @@ static void resizestack(lua_State *L, MSize n)
61 L->base = (TValue *)((char *)L->base + delta); 61 L->base = (TValue *)((char *)L->base + delta);
62 L->top = (TValue *)((char *)L->top + delta); 62 L->top = (TValue *)((char *)L->top + delta);
63 for (up = gcref(L->openupval); up != NULL; up = gcnext(up)) 63 for (up = gcref(L->openupval); up != NULL; up = gcnext(up))
64 gco2uv(up)->v = (TValue *)((char *)gco2uv(up)->v + delta); 64 setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta));
65 if (obj2gco(L) == gcref(G(L)->jit_L)) 65 if (obj2gco(L) == gcref(G(L)->jit_L))
66 setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta); 66 setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta);
67} 67}