mruby-os-memsize/memsize.c: fix irep size calculation

Need to count the following as well:

- size of pool values
- size of reps array
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-08-01 23:03:56 +09:00
parent 1bc8ef903e
commit a2649652f1
+15 -4
View File
@@ -16,13 +16,24 @@ static size_t
os_memsize_of_irep(mrb_state* state, const struct mrb_irep *irep)
{
size_t size;
int i;
size = (irep->slen * sizeof(mrb_sym)) +
(irep->plen * sizeof(mrb_code)) +
(irep->ilen * sizeof(mrb_code));
(irep->plen * sizeof(mrb_pool_value)) +
(irep->ilen * sizeof(mrb_code)) +
(irep->rlen * sizeof(struct mrb_irep*));
for (i = 0; i < irep->rlen; i++) {
for (int i = 0; i < irep->plen; i++) {
const mrb_pool_value *p = &irep->pool[i];
if ((p->tt & IREP_TT_NFLAG) == 0) { /* string pool value */
size += (p->tt>>2);
}
else if (p->tt == IREP_TT_BIGINT) { /* bigint pool value */
size += p->u.str[0];
}
}
for (int i = 0; i < irep->rlen; i++) {
size += sizeof(struct mrb_irep); /* size of irep structure */
size += os_memsize_of_irep(state, irep->reps[i]);
}
return size;