diff options
| author | Daniel Bovensiepen <[email protected]> | 2012-12-07 16:19:52 +0800 |
|---|---|---|
| committer | Daniel Bovensiepen <[email protected]> | 2012-12-07 16:19:52 +0800 |
| commit | bef73cc54f044e16caf6bc1ba16ed0bf779c5ade (patch) | |
| tree | 3f4fe67c6180bf2df1b61e87b0da24cb3c6e9866 /src/load.c | |
| parent | bb6d42d987d2d03e20b7f0c8c8cd081a1082095b (diff) | |
| parent | f1ed1436240a2d0d3d45a7061ade26cdc25be352 (diff) | |
| download | mruby-bef73cc54f044e16caf6bc1ba16ed0bf779c5ade.tar.gz mruby-bef73cc54f044e16caf6bc1ba16ed0bf779c5ade.zip | |
Integrate refactoring of commit f1ed1436240a2d0d3d45a7061ade26cdc25be352
Diffstat (limited to 'src/load.c')
| -rw-r--r-- | src/load.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/load.c b/src/load.c index 3cd8d91b0..2b5f58001 100644 --- a/src/load.c +++ b/src/load.c @@ -47,7 +47,7 @@ static unsigned char* rite_fgets(RiteFILE*,unsigned char*,int,int); static int load_rite_header(FILE*,rite_binary_header*,unsigned char*); static int load_rite_irep_record(mrb_state*, RiteFILE*,unsigned char*,uint32_t*); static int read_rite_header(mrb_state*,unsigned char*,rite_binary_header*); -static int read_rite_irep_record(mrb_state*,unsigned char*,mrb_irep*,uint32_t*); +static int read_rite_irep_record(mrb_state*,unsigned char*,uint32_t*); static unsigned char @@ -321,7 +321,7 @@ read_rite_header(mrb_state *mrb, unsigned char *bin, rite_binary_header* bin_he } static int -read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32_t* len) +read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len) { int i, ret = MRB_DUMP_OK; char *buf; @@ -329,7 +329,9 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 uint16_t crc, tt, pdl, snl, offset, bufsize=MRB_DUMP_DEFAULT_STR_LEN; mrb_int fix_num; mrb_float f; + int plen; int ai = mrb_gc_arena_save(mrb); + mrb_irep *irep = mrb_add_irep(mrb); recordStart = src; buf = (char *)mrb_malloc(mrb, bufsize); @@ -378,16 +380,16 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 //POOL BLOCK pStart = src; - irep->plen = bin_to_uint32(src); //pool length + plen = bin_to_uint32(src); //pool length src += MRB_DUMP_SIZE_OF_LONG; - if (irep->plen > 0) { - irep->pool = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value) * irep->plen); + if (plen > 0) { + irep->pool = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value) * plen); if (irep->pool == NULL) { ret = MRB_DUMP_INVALID_IREP; goto error_exit; } - for (i=0; i<irep->plen; i++) { + for (i=0; i<plen; i++) { tt = *src; //pool TT src += sizeof(unsigned char); pdl = bin_to_uint16(src); //pool data length @@ -430,6 +432,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 irep->pool[i] = mrb_nil_value(); break; } + irep->plen++; + mrb_gc_arena_restore(mrb, ai); } } crc = calc_crc_16_ccitt((unsigned char*)pStart, src - pStart); //Calculate CRC @@ -485,7 +489,6 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32 *len = src - recordStart; error_exit: - mrb_gc_arena_restore(mrb, ai); if (buf) mrb_free(mrb, buf); @@ -509,25 +512,14 @@ mrb_read_irep(mrb_state *mrb, const char *bin) //Read File Header Section if ((nirep = read_rite_header(mrb, src, &bin_header)) < 0) return nirep; - - mrb_add_irep(mrb, sirep + nirep); - - for (n=0,i=sirep; n<nirep; n++,i++) { - static const mrb_irep mrb_irep_zero = { 0 }; - if ((mrb->irep[i] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep))) == NULL) { - ret = MRB_DUMP_GENERAL_FAILURE; - goto error_exit; - } - *mrb->irep[i] = mrb_irep_zero; - } + src += sizeof(bin_header) + MRB_DUMP_SIZE_OF_SHORT; //header + crc //Read Binary Data Section for (n=0,i=sirep; n<nirep; n++,i++) { src += MRB_DUMP_SIZE_OF_LONG; //record ren - if ((ret = read_rite_irep_record(mrb, src, mrb->irep[i], &len)) != MRB_DUMP_OK) + if ((ret = read_rite_irep_record(mrb, src, &len)) != MRB_DUMP_OK) goto error_exit; - mrb->irep[mrb->irep_len++]->idx = i; src += len; } if (0 != bin_to_uint32(src)) { //dummy record len @@ -536,7 +528,7 @@ mrb_read_irep(mrb_state *mrb, const char *bin) error_exit: if (ret != MRB_DUMP_OK) { - for (n=0,i=sirep; n<nirep; n++,i++) { + for (n=0,i=sirep; i<mrb->irep_len; n++,i++) { if (mrb->irep[i]) { if (mrb->irep[i]->iseq) mrb_free(mrb, mrb->irep[i]->iseq); @@ -550,6 +542,7 @@ error_exit: mrb_free(mrb, mrb->irep[i]); } } + // mrb->irep_len = sirep; return ret; } return sirep + hex_to_uint8(bin_header.sirep); |
