From 87423130795fcfbc436ac735b3b44081cc5d57a4 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 29 Mar 2013 16:21:12 +0900 Subject: Remove RiteFile as no used. --- src/load.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index 4a9947e75..c58dde4ce 100644 --- a/src/load.c +++ b/src/load.c @@ -17,16 +17,6 @@ #include "mruby/proc.h" #include "mruby/string.h" -#ifdef ENABLE_STDIO -typedef struct _RiteFILE -{ - FILE* fp; - unsigned char buf[256]; - int cnt; - int readlen; -} RiteFILE; -#endif - #ifndef _WIN32 # if SIZE_MAX < UINT32_MAX # error "It can't be run this code on this environment (SIZE_MAX < UINT32_MAX)" -- cgit v1.2.3 From 2b6e9ee556fabebf732ba24fe1de2250b6a6dda2 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 29 Mar 2013 16:26:00 +0900 Subject: Modify the type of line-number to uint16_t. Type short is not portable. And it cannot be more than UINT16_MAX because of the mrbc binary format. --- include/mruby/irep.h | 2 +- src/codegen.c | 2 +- src/load.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/load.c') diff --git a/include/mruby/irep.h b/include/mruby/irep.h index 982ab4ac2..0305b9e0b 100644 --- a/include/mruby/irep.h +++ b/include/mruby/irep.h @@ -23,7 +23,7 @@ typedef struct mrb_irep { /* debug info */ const char *filename; - short *lines; + uint16_t *lines; size_t ilen, plen, slen; } mrb_irep; diff --git a/src/codegen.c b/src/codegen.c index cff3b3ce4..e5b1802a1 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -2401,7 +2401,7 @@ scope_finish(codegen_scope *s) irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc); irep->ilen = s->pc; if (s->lines) { - irep->lines = (short *)codegen_realloc(s, s->lines, sizeof(short)*s->pc); + irep->lines = (uint16_t *)codegen_realloc(s, s->lines, sizeof(uint16_t)*s->pc); } else { irep->lines = 0; diff --git a/src/load.c b/src/load.c index c58dde4ce..66182e10f 100644 --- a/src/load.c +++ b/src/load.c @@ -226,7 +226,7 @@ read_rite_lineno_record(mrb_state *mrb, const uint8_t *bin, size_t irepno, uint3 int ret; size_t i, fname_len, niseq; char *fname; - short *lines; + uint16_t *lines; ret = MRB_DUMP_OK; *len = 0; @@ -249,7 +249,7 @@ read_rite_lineno_record(mrb_state *mrb, const uint8_t *bin, size_t irepno, uint3 bin += sizeof(uint32_t); // niseq *len += sizeof(uint32_t); - lines = (short *)mrb_malloc(mrb, niseq * sizeof(short)); + lines = (uint16_t *)mrb_malloc(mrb, niseq * sizeof(uint16_t)); for (i = 0; i < niseq; i++) { lines[i] = bin_to_uint16(bin); bin += sizeof(uint16_t); // niseq -- cgit v1.2.3 From 9074983b22f835260d914bc3b856b08d312646c8 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 29 Mar 2013 16:28:13 +0900 Subject: Reduce temporary memory allocations. They are redundant. --- src/load.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index 66182e10f..2596325df 100644 --- a/src/load.c +++ b/src/load.c @@ -35,21 +35,12 @@ read_rite_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len) { int ret; size_t i; - char *char_buf; const uint8_t *src = bin; - uint16_t tt, pool_data_len, snl, buf_size = MRB_DUMP_DEFAULT_STR_LEN; - mrb_int fix_num; - mrb_float f; + uint16_t tt, pool_data_len, snl; size_t plen; int ai = mrb_gc_arena_save(mrb); mrb_irep *irep = mrb_add_irep(mrb); - char_buf = (char *)mrb_malloc(mrb, buf_size); - if (char_buf == NULL) { - ret = MRB_DUMP_GENERAL_FAILURE; - goto error_exit; - } - // skip record size src += sizeof(uint32_t); @@ -88,34 +79,23 @@ read_rite_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len) } for (i = 0; i < plen; i++) { + mrb_value s; tt = *src++; //pool TT pool_data_len = bin_to_uint16(src); //pool data length src += sizeof(uint16_t); - if (pool_data_len > buf_size - 1) { - mrb_free(mrb, char_buf); - buf_size = pool_data_len + 1; - char_buf = (char *)mrb_malloc(mrb, buf_size); - if (char_buf == NULL) { - ret = MRB_DUMP_GENERAL_FAILURE; - goto error_exit; - } - } - memcpy(char_buf, src, pool_data_len); + s = mrb_str_new(mrb, (char *)src, pool_data_len); src += pool_data_len; - char_buf[pool_data_len] = '\0'; switch (tt) { //pool data case MRB_TT_FIXNUM: - fix_num = str_to_mrb_int(char_buf); - irep->pool[i] = mrb_fixnum_value(fix_num); + irep->pool[i] = mrb_str_to_inum(mrb, s, 10, FALSE); break; case MRB_TT_FLOAT: - f = str_to_mrb_float(char_buf); - irep->pool[i] = mrb_float_value(f); + irep->pool[i] = mrb_float_value(mrb_str_to_dbl(mrb, s, FALSE)); break; case MRB_TT_STRING: - irep->pool[i] = mrb_str_new(mrb, char_buf, pool_data_len); + irep->pool[i] = s; break; default: @@ -137,10 +117,6 @@ read_rite_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len) goto error_exit; } - for (i = 0; i < irep->slen; i++) { - static const mrb_sym mrb_sym_zero = { 0 }; - *irep->syms = mrb_sym_zero; - } for (i = 0; i < irep->slen; i++) { snl = bin_to_uint16(src); //symbol name length src += sizeof(uint16_t); @@ -150,26 +126,16 @@ read_rite_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len) continue; } - if (snl > buf_size - 1) { - mrb_free(mrb, char_buf); - buf_size = snl + 1; - char_buf = (char *)mrb_malloc(mrb, buf_size); - if (char_buf == NULL) { - ret = MRB_DUMP_GENERAL_FAILURE; - goto error_exit; - } - } - memcpy(char_buf, src, snl); //symbol name + irep->syms[i] = mrb_intern2(mrb, (char *)src, snl); src += snl; - char_buf[snl] = '\0'; - irep->syms[i] = mrb_intern2(mrb, char_buf, snl); + + mrb_gc_arena_restore(mrb, ai); } } *len = src - bin; ret = MRB_DUMP_OK; error_exit: - mrb_free(mrb, char_buf); return ret; } -- cgit v1.2.3 From 24eb120148921871b3e4e6ea812272782d2e0757 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 29 Mar 2013 16:32:15 +0900 Subject: Add CHAR_BIT check. There are uint8_t to char conversions. --- src/load.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/load.c') diff --git a/src/load.c b/src/load.c index 2596325df..a2f685742 100644 --- a/src/load.c +++ b/src/load.c @@ -23,6 +23,10 @@ # endif #endif +#if CHAR_BIT != 8 +# error This code assumes CHAR_BIT == 8 +#endif + static size_t offset_crc_body() { -- cgit v1.2.3