Change the catch handler address to 32 bits
Follow commit .
MODIFY
include/mruby/irep.h
include/mruby/irep.h
@@ -47,9 +47,9 @@ enum mrb_catch_type {
struct mrb_irep_catch_handler {
uint8_t type; /* enum mrb_catch_type */
- uint8_t begin[2]; /* The starting address to match the hander. Includes this. */
- uint8_t end[2]; /* The endpoint address that matches the hander. Not Includes this. */
- uint8_t target[2]; /* The address to jump to if a match is made. */
+ uint8_t begin[4]; /* The starting address to match the hander. Includes this. */
+ uint8_t end[4]; /* The endpoint address that matches the hander. Not Includes this. */
+ uint8_t target[4]; /* The address to jump to if a match is made. */
};
/* Program data array struct */
@@ -139,6 +139,9 @@ mrb_irep_catch_handler_table(const struct mrb_irep *irep)
}
}
+#define mrb_irep_catch_handler_pack(n, v) uint32_to_bin(n, v)
+#define mrb_irep_catch_handler_unpack(v) bin_to_uint32(v)
+
MRB_END_DECL
#endif /* MRUBY_IREP_H */

MODIFY
mrbgems/mruby-compiler/core/codegen.c
mrbgems/mruby-compiler/core/codegen.c
@@ -3229,9 +3229,9 @@ catch_handler_set(codegen_scope *s, int ent, enum mrb_catch_type type, uint32_t
e = &s->catch_table[ent];
uint8_to_bin(type, &e->type);
- uint16_to_bin(begin, e->begin);
- uint16_to_bin(end, e->end);
- uint16_to_bin(target, e->target);
+ mrb_irep_catch_handler_pack(begin, e->begin);
+ mrb_irep_catch_handler_pack(end, e->end);
+ mrb_irep_catch_handler_pack(target, e->target);
}
static struct RProc*

MODIFY
src/dump.c
src/dump.c
@@ -277,7 +277,7 @@ write_catch_table_block(mrb_state *mrb, const mrb_irep *irep, uint8_t *buf)
{
uint8_t *cur = buf;
const struct mrb_irep_catch_handler *e = mrb_irep_catch_handler_table(irep);
- mrb_static_assert1(sizeof(*e) == 7);
+ mrb_static_assert1(sizeof(*e) == 13);
if (e == NULL) return 0;
/* irep->clen has already been written before iseq block */

MODIFY
src/load.c
src/load.c
@@ -107,7 +107,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
if (irep->ilen > 0) {
size_t data_len = sizeof(mrb_code) * irep->ilen +
sizeof(struct mrb_irep_catch_handler) * irep->clen;
- mrb_static_assert1(sizeof(struct mrb_irep_catch_handler) == 7);
+ mrb_static_assert1(sizeof(struct mrb_irep_catch_handler) == 13);
if (SIZE_ERROR_MUL(irep->ilen, sizeof(mrb_code))) {
return NULL;
}

MODIFY
src/vm.c
src/vm.c
@@ -813,7 +813,7 @@ catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_
e = mrb_irep_catch_handler_table(irep) + cnt - 1;
for (; cnt > 0; cnt --, e --) {
if (((UINT32_C(1) << e->type) & filter) &&
- catch_cover_p(xpc, bin_to_uint16(e->begin), bin_to_uint16(e->end))) {
+ catch_cover_p(xpc, mrb_irep_catch_handler_unpack(e->begin), mrb_irep_catch_handler_unpack(e->end))) {
return e;
}
}
@@ -1312,7 +1312,7 @@ RETRY_TRY_BLOCK:
ch = catch_handler_find(mrb, mrb->c->ci, pc, MRB_CATCH_FILTER_ENSURE);
if (ch) {
/* avoiding a jump from a catch handler into the same handler */
- if (a < bin_to_uint16(ch->begin) || a >= bin_to_uint16(ch->end)) {
+ if (a < mrb_irep_catch_handler_unpack(ch->begin) || a >= mrb_irep_catch_handler_unpack(ch->end)) {
THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, proc, mrb_fixnum_value(a));
}
}
@@ -2009,7 +2009,7 @@ RETRY_TRY_BLOCK:
mrb->c->stack = ci[1].stackent;
}
mrb_stack_extend(mrb, irep->nregs);
- pc = irep->iseq + bin_to_uint16(ch->target);
+ pc = irep->iseq + mrb_irep_catch_handler_unpack(ch->target);
}
else {
mrb_int acc;

Change the catch handler address to 32 bits

Follow commit 7150c6753933f12a2ba63769fb7b3a44cfcddd3d .