aboutsummaryrefslogtreecommitdiff
path: root/src/lj_bcwrite.c
diff options
context:
space:
mode:
authorMike Pall <mike>2025-03-11 23:04:30 +0100
committerMike Pall <mike>2025-03-11 23:04:30 +0100
commit538a82133ad6fddfd0ca64de167c4aca3bc1a2da (patch)
tree22fd80543291b6b51ba9a6f841719bab7ed7b3bd /src/lj_bcwrite.c
parent84cb21ffaf648b472ff3884556e2c413e8abe179 (diff)
downloadluajit-v2.1.tar.gz
luajit-v2.1.tar.bz2
luajit-v2.1.zip
Change handling of nil value markers in template tables.HEADv2.1
Reported by Bernhard M. Wiedemann. #1348 #1155 Fixes from Peter Cawley, Christian Clason, Lewis Russell.
Diffstat (limited to 'src/lj_bcwrite.c')
-rw-r--r--src/lj_bcwrite.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c
index de200ef4..ec6f13c8 100644
--- a/src/lj_bcwrite.c
+++ b/src/lj_bcwrite.c
@@ -71,6 +71,8 @@ static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow)
71 *p++ = BCDUMP_KTAB_NUM; 71 *p++ = BCDUMP_KTAB_NUM;
72 p = lj_strfmt_wuleb128(p, o->u32.lo); 72 p = lj_strfmt_wuleb128(p, o->u32.lo);
73 p = lj_strfmt_wuleb128(p, o->u32.hi); 73 p = lj_strfmt_wuleb128(p, o->u32.hi);
74 } else if (tvistab(o)) { /* Write the nil value marker as a nil. */
75 *p++ = BCDUMP_KTAB_NIL;
74 } else { 76 } else {
75 lj_assertBCW(tvispri(o), "unhandled type %d", itype(o)); 77 lj_assertBCW(tvispri(o), "unhandled type %d", itype(o));
76 *p++ = BCDUMP_KTAB_NIL+~itype(o); 78 *p++ = BCDUMP_KTAB_NIL+~itype(o);
@@ -133,7 +135,7 @@ static void bcwrite_ktab_sorted_hash(BCWriteCtx *ctx, Node *node, MSize nhash)
133 TValue **heap = ctx->heap; 135 TValue **heap = ctx->heap;
134 MSize i = nhash; 136 MSize i = nhash;
135 for (;; node--) { /* Build heap. */ 137 for (;; node--) { /* Build heap. */
136 if (!tvisnil(&node->key)) { 138 if (!tvisnil(&node->val)) {
137 bcwrite_ktabk_heap_insert(heap, --i, nhash, &node->key); 139 bcwrite_ktabk_heap_insert(heap, --i, nhash, &node->key);
138 if (i == 0) break; 140 if (i == 0) break;
139 } 141 }
@@ -163,7 +165,7 @@ static void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t)
163 MSize i, hmask = t->hmask; 165 MSize i, hmask = t->hmask;
164 Node *node = noderef(t->node); 166 Node *node = noderef(t->node);
165 for (i = 0; i <= hmask; i++) 167 for (i = 0; i <= hmask; i++)
166 nhash += !tvisnil(&node[i].key); 168 nhash += !tvisnil(&node[i].val);
167 } 169 }
168 /* Write number of array slots and hash slots. */ 170 /* Write number of array slots and hash slots. */
169 p = lj_strfmt_wuleb128(p, narray); 171 p = lj_strfmt_wuleb128(p, narray);
@@ -184,7 +186,7 @@ static void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t)
184 } else { 186 } else {
185 MSize i = nhash; 187 MSize i = nhash;
186 for (;; node--) 188 for (;; node--)
187 if (!tvisnil(&node->key)) { 189 if (!tvisnil(&node->val)) {
188 bcwrite_ktabk(ctx, &node->key, 0); 190 bcwrite_ktabk(ctx, &node->key, 0);
189 bcwrite_ktabk(ctx, &node->val, 1); 191 bcwrite_ktabk(ctx, &node->val, 1);
190 if (--i == 0) break; 192 if (--i == 0) break;