aboutsummaryrefslogtreecommitdiff
path: root/src/lj_parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_parse.c')
-rw-r--r--src/lj_parse.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c
index f4116380..70097598 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -1725,7 +1725,7 @@ static void expr_table(LexState *ls, ExpDesc *e)
1725 FuncState *fs = ls->fs; 1725 FuncState *fs = ls->fs;
1726 BCLine line = ls->linenumber; 1726 BCLine line = ls->linenumber;
1727 GCtab *t = NULL; 1727 GCtab *t = NULL;
1728 int vcall = 0, needarr = 0; 1728 int vcall = 0, needarr = 0, fixt = 0;
1729 uint32_t narr = 1; /* First array index. */ 1729 uint32_t narr = 1; /* First array index. */
1730 uint32_t nhash = 0; /* Number of hash entries. */ 1730 uint32_t nhash = 0; /* Number of hash entries. */
1731 BCReg freg = fs->freereg; 1731 BCReg freg = fs->freereg;
@@ -1769,10 +1769,9 @@ static void expr_table(LexState *ls, ExpDesc *e)
1769 lj_gc_anybarriert(fs->L, t); 1769 lj_gc_anybarriert(fs->L, t);
1770 if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */ 1770 if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */
1771 expr_kvalue(fs, v, &val); 1771 expr_kvalue(fs, v, &val);
1772 /* Mark nil value with table value itself to preserve the key. */ 1772 } else { /* Otherwise create dummy string key (avoids lj_tab_newkey). */
1773 if (key.k == VKSTR && tvisnil(v)) settabV(fs->L, v, t); 1773 settabV(fs->L, v, t); /* Preserve key with table itself as value. */
1774 } else { /* Preserve the key for the following non-const store. */ 1774 fixt = 1; /* Fix this later, after all resizes. */
1775 settabV(fs->L, v, t);
1776 goto nonconst; 1775 goto nonconst;
1777 } 1776 }
1778 } else { 1777 } else {
@@ -1814,6 +1813,17 @@ static void expr_table(LexState *ls, ExpDesc *e)
1814 } else { 1813 } else {
1815 if (needarr && t->asize < narr) 1814 if (needarr && t->asize < narr)
1816 lj_tab_reasize(fs->L, t, narr-1); 1815 lj_tab_reasize(fs->L, t, narr-1);
1816 if (fixt) { /* Fix value for dummy keys in template table. */
1817 Node *node = noderef(t->node);
1818 uint32_t i, hmask = t->hmask;
1819 for (i = 0; i <= hmask; i++) {
1820 Node *n = &node[i];
1821 if (tvistab(&n->val)) {
1822 lj_assertFS(tabV(&n->val) == t, "bad dummy key in template table");
1823 setnilV(&n->val); /* Turn value into nil. */
1824 }
1825 }
1826 }
1817 lj_gc_check(fs->L); 1827 lj_gc_check(fs->L);
1818 } 1828 }
1819} 1829}