mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
should not free() static iseq from cdump
This commit is contained in:
@@ -12,10 +12,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct mrb_irep {
|
||||
int idx;
|
||||
|
||||
int nlocals;
|
||||
int nregs;
|
||||
int idx:16;
|
||||
int nlocals:16;
|
||||
int nregs:16;
|
||||
int flags:8;
|
||||
|
||||
mrb_code *iseq;
|
||||
mrb_value *pool;
|
||||
@@ -28,6 +28,8 @@ typedef struct mrb_irep {
|
||||
int ilen, plen, slen;
|
||||
} mrb_irep;
|
||||
|
||||
#define MRB_ISEQ_NO_FREE 1
|
||||
|
||||
void mrb_add_irep(mrb_state *mrb, int n);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
+13
-6
@@ -113,6 +113,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
|
||||
|
||||
SOURCE_CODE0 (" ai = mrb->arena_idx;");
|
||||
SOURCE_CODE0 (" irep = mrb->irep[idx] = mrb_malloc(mrb, sizeof(mrb_irep));");
|
||||
SOURCE_CODE0 (" irep->flags = MRB_ISEQ_NO_FREE;");
|
||||
SOURCE_CODE0 (" irep->idx = idx++;");
|
||||
SOURCE_CODE (" irep->nlocals = %d;", irep->nlocals);
|
||||
SOURCE_CODE (" irep->nregs = %d;", irep->nregs);
|
||||
@@ -124,13 +125,19 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
|
||||
SOURCE_CODE (" irep->syms = mrb_malloc(mrb, sizeof(mrb_sym)*%d);", irep->slen);
|
||||
for (n=0; n<irep->slen; n++)
|
||||
if (irep->syms[n]) {
|
||||
SOURCE_CODE (" irep->syms[%d] = mrb_intern(mrb, \"%s\");", n, mrb_sym2name(mrb, irep->syms[n]));
|
||||
const char *name;
|
||||
int len;
|
||||
|
||||
name = mrb_sym2name_len(mrb, irep->syms[n], &len);
|
||||
SOURCE_CODE (" irep->syms[%d] = mrb_intern2(mrb, \"%s\", %d);", n, name, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
SOURCE_CODE0 (" irep->syms = NULL;");
|
||||
|
||||
SOURCE_CODE (" irep->plen = %d;", irep->plen);
|
||||
SOURCE_CODE0 (" irep->pool = NULL;");
|
||||
SOURCE_CODE0 (" mrb->irep_len = idx;");
|
||||
SOURCE_CODE0 (" irep->plen = 0;");
|
||||
if(irep->plen > 0) {
|
||||
SOURCE_CODE (" irep->pool = mrb_malloc(mrb, sizeof(mrb_value)*%d);", irep->plen);
|
||||
for (n=0; n<irep->plen; n++) {
|
||||
@@ -148,16 +155,16 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
|
||||
}
|
||||
}
|
||||
memset(buf, 0, buf_len);
|
||||
SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break;
|
||||
SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n]));
|
||||
SOURCE_CODE0 (" mrb->arena_idx = ai;");
|
||||
break;
|
||||
/* TODO MRB_TT_REGEX */
|
||||
default: break;
|
||||
}
|
||||
SOURCE_CODE0(" irep->plen++;");
|
||||
}
|
||||
}
|
||||
else
|
||||
SOURCE_CODE0 (" irep->pool = NULL;");
|
||||
SOURCE_CODE0 (" mrb->irep_len = idx;");
|
||||
SOURCE_CODE0 (" mrb->arena_idx = ai;");
|
||||
SOURCE_CODE0("");
|
||||
return MRB_CDUMP_OK;
|
||||
}
|
||||
|
||||
+2
-1
@@ -92,7 +92,8 @@ mrb_close(mrb_state *mrb)
|
||||
mrb_free(mrb, mrb->stbase);
|
||||
mrb_free(mrb, mrb->cibase);
|
||||
for (i=0; i<mrb->irep_len; i++) {
|
||||
mrb_free(mrb, mrb->irep[i]->iseq);
|
||||
if (!(mrb->irep[i]->flags & MRB_ISEQ_NO_FREE))
|
||||
mrb_free(mrb, mrb->irep[i]->iseq);
|
||||
mrb_free(mrb, mrb->irep[i]->pool);
|
||||
mrb_free(mrb, mrb->irep[i]->syms);
|
||||
mrb_free(mrb, mrb->irep[i]->lines);
|
||||
|
||||
Reference in New Issue
Block a user