allow NULL (no variable) in lvar section of mrb format; fix #2294

This fix use UINT16_MAX for NULL symbol tag, that means maximum symbol length
is not UINT16_MAX-1.
parent 91a025b1
......@@ -94,6 +94,8 @@ struct rite_section_lv_header {
RITE_SECTION_HEADER;
};
#define RITE_LV_NULL_MARK UINT16_MAX
struct rite_binary_footer {
RITE_SECTION_HEADER;
};
......
......@@ -703,6 +703,7 @@ create_lv_sym_table(mrb_state *mrb, const mrb_irep *irep, mrb_sym **syms, uint32
for (i = 0; i + 1 < irep->nlocals; ++i) {
mrb_sym const name = irep->lv[i].name;
if (name == 0) continue;
if (find_filename_index(*syms, *syms_len, name) != -1) continue;
++(*syms_len);
......@@ -744,12 +745,18 @@ write_lv_record(mrb_state *mrb, const mrb_irep *irep, uint8_t **start, mrb_sym c
size_t i;
for (i = 0; i + 1 < irep->nlocals; ++i) {
if (irep->lv[i].name == 0) {
cur += uint16_to_bin(RITE_LV_NULL_MARK, cur);
cur += uint16_to_bin(0, cur);
}
else {
int const sym_idx = find_filename_index(syms, syms_len, irep->lv[i].name);
mrb_assert(sym_idx != -1); /* local variable name must be in syms */
cur += uint16_to_bin(sym_idx, cur);
cur += uint16_to_bin(irep->lv[i].r, cur);
}
}
for (i = 0; i < irep->rlen; ++i) {
write_lv_record(mrb, irep->reps[i], &cur, syms, syms_len);
......
......@@ -411,12 +411,18 @@ read_lv_record(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, size_t *rec
for (i = 0; i + 1< irep->nlocals; ++i) {
uint16_t const sym_idx = bin_to_uint16(bin);
bin += sizeof(uint16_t);
if (sym_idx == RITE_LV_NULL_MARK) {
irep->lv[i].name = 0;
irep->lv[i].r = 0;
}
else {
if (sym_idx >= syms_len) {
return MRB_DUMP_GENERAL_FAILURE;
}
irep->lv[i].name = syms[sym_idx];
irep->lv[i].r = bin_to_uint16(bin);
}
bin += sizeof(uint16_t);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment