diff options
| author | Yuichiro MASUI <[email protected]> | 2013-03-08 18:55:15 +0900 |
|---|---|---|
| committer | Yuichiro MASUI <[email protected]> | 2013-03-08 18:55:15 +0900 |
| commit | 814094230cb49ac3699296e49e03b6b19c5fcf10 (patch) | |
| tree | 1637bb2659454e74f97663e63088497a70d81ccc | |
| parent | 284258367881d74f784485c2e5d282f4f5d490a5 (diff) | |
| download | mruby-814094230cb49ac3699296e49e03b6b19c5fcf10.tar.gz mruby-814094230cb49ac3699296e49e03b6b19c5fcf10.zip | |
Change unsigned char to uint8_t
| -rw-r--r-- | include/mruby/dump.h | 38 | ||||
| -rw-r--r-- | mrblib/init_mrblib.c | 2 | ||||
| -rw-r--r-- | src/dump.c | 42 | ||||
| -rw-r--r-- | src/load.c | 56 | ||||
| -rw-r--r-- | test/init_mrbtest.c | 2 |
5 files changed, 70 insertions, 70 deletions
diff --git a/include/mruby/dump.h b/include/mruby/dump.h index 91ad76a46..a536cb46b 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -22,7 +22,7 @@ int mrb_dump_irep_binary(mrb_state*, int, FILE*); int mrb_dump_irep_cfunc(mrb_state *mrb, int n, FILE *f, const char *initname); int mrb_read_irep_file(mrb_state*, FILE*); #endif -int mrb_read_irep(mrb_state*, const unsigned char*); +int mrb_read_irep(mrb_state*, const uint8_t*); #ifdef ENABLE_STDIO mrb_value mrb_load_irep_file(mrb_state*,FILE*); @@ -60,18 +60,18 @@ mrb_value mrb_load_irep_file(mrb_state*,FILE*); // Rite binary header struct rite_binary_header { - unsigned char binary_identify[4]; // Rite Binary Identify - unsigned char binary_version[4]; // Rite Binary Format Version - unsigned char binary_crc[2]; // Rite Binary CRC - unsigned char binary_size[4]; // Rite Binary Size - unsigned char compiler_name[4]; // Rite Compiler name - unsigned char compiler_version[4]; + uint8_t binary_identify[4]; // Rite Binary Identify + uint8_t binary_version[4]; // Rite Binary Format Version + uint8_t binary_crc[2]; // Rite Binary CRC + uint8_t binary_size[4]; // Rite Binary Size + uint8_t compiler_name[4]; // Rite Compiler name + uint8_t compiler_version[4]; }; // Rite section header #define RITE_SECTION_HEADER \ - unsigned char section_identify[4]; \ - unsigned char section_size[4]; + uint8_t section_identify[4]; \ + uint8_t section_size[4]; struct rite_section_header { RITE_SECTION_HEADER; @@ -80,9 +80,9 @@ struct rite_section_header { struct rite_section_irep_header { RITE_SECTION_HEADER; - unsigned char rite_version[4]; // Rite Instruction Specification Version - unsigned char nirep[2]; // Number of ireps - unsigned char sirep[2]; // Start index + uint8_t rite_version[4]; // Rite Instruction Specification Version + uint8_t nirep[2]; // Number of ireps + uint8_t sirep[2]; // Start index }; struct rite_binary_footer { @@ -90,14 +90,14 @@ struct rite_binary_footer { }; static inline int -uint8_to_bin(uint8_t s, unsigned char *bin) +uint8_to_bin(uint8_t s, uint8_t *bin) { *bin = s; return sizeof(uint8_t); } static inline int -uint16_to_bin(uint16_t s, unsigned char *bin) +uint16_to_bin(uint16_t s, uint8_t *bin) { *bin++ = (s >> 8) & 0xff; *bin = s & 0xff; @@ -105,7 +105,7 @@ uint16_to_bin(uint16_t s, unsigned char *bin) } static inline int -uint32_to_bin(uint32_t l, unsigned char *bin) +uint32_to_bin(uint32_t l, uint8_t *bin) { *bin++ = (l >> 24) & 0xff; *bin++ = (l >> 16) & 0xff; @@ -115,7 +115,7 @@ uint32_to_bin(uint32_t l, unsigned char *bin) } static inline uint32_t -bin_to_uint32(const unsigned char *bin) +bin_to_uint32(const uint8_t *bin) { return (uint32_t)bin[0] << 24 | (uint32_t)bin[1] << 16 | @@ -124,21 +124,21 @@ bin_to_uint32(const unsigned char *bin) } static inline uint16_t -bin_to_uint16(const unsigned char *bin) +bin_to_uint16(const uint8_t *bin) { return (uint16_t)bin[0] << 8 | (uint16_t)bin[1]; } static inline uint8_t -bin_to_uint8(const unsigned char *bin) +bin_to_uint8(const uint8_t *bin) { return (uint8_t)bin[0]; } /* crc.c */ uint32_t -calc_crc_16_ccitt(const unsigned char *src, uint32_t nbytes, uint16_t crcwk); +calc_crc_16_ccitt(const uint8_t *src, uint32_t nbytes, uint16_t crcwk); #if defined(__cplusplus) } /* extern "C" { */ diff --git a/mrblib/init_mrblib.c b/mrblib/init_mrblib.c index fe95326bf..f65b185a3 100644 --- a/mrblib/init_mrblib.c +++ b/mrblib/init_mrblib.c @@ -4,7 +4,7 @@ #include "mruby/string.h" #include "mruby/proc.h" -extern const unsigned char mrblib_irep[]; +extern const uint8_t mrblib_irep[]; void mrb_init_mrblib(mrb_state *mrb) diff --git a/src/dump.c b/src/dump.c index 1e0c32708..bf5a9b6f4 100644 --- a/src/dump.c +++ b/src/dump.c @@ -28,9 +28,9 @@ get_irep_header_size(mrb_state *mrb) } static size_t -write_irep_header(mrb_state *mrb, mrb_irep *irep, unsigned char *buf) +write_irep_header(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) { - unsigned char *cur = buf; + uint8_t *cur = buf; cur += uint32_to_bin(get_irep_record_size(mrb, irep), cur); /* record size */ cur += uint16_to_bin((uint16_t)irep->nlocals, cur); /* number of local variable */ @@ -50,9 +50,9 @@ get_iseq_block_size(mrb_state *mrb, mrb_irep *irep) } static int -write_iseq_block(mrb_state *mrb, mrb_irep *irep, unsigned char *buf) +write_iseq_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) { - unsigned char *cur = buf; + uint8_t *cur = buf; int iseq_no; cur += uint32_to_bin(irep->ilen, cur); /* number of opcode */ @@ -101,10 +101,10 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep) } static int -write_pool_block(mrb_state *mrb, mrb_irep *irep, unsigned char *buf) +write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) { int result, pool_no; - unsigned char *cur = buf; + uint8_t *cur = buf; size_t buf_size, len; mrb_value str; char *char_buf = NULL; @@ -184,10 +184,10 @@ get_syms_block_size(mrb_state *mrb, mrb_irep *irep) } static int -write_syms_block(mrb_state *mrb, mrb_irep *irep, unsigned char *buf) +write_syms_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) { int result, sym_no, len, buf_size; - unsigned char *cur = buf; + uint8_t *cur = buf; uint16_t nlen; char *char_buf = NULL; const char *name; @@ -248,7 +248,7 @@ get_irep_record_size(mrb_state *mrb, mrb_irep *irep) } static int -write_irep_record(mrb_state *mrb, mrb_irep *irep, unsigned char* bin, uint32_t *irep_record_size) +write_irep_record(mrb_state *mrb, mrb_irep *irep, uint8_t* bin, uint32_t *irep_record_size) { if (irep == NULL) { return MRB_DUMP_INVALID_IREP; @@ -271,7 +271,7 @@ write_irep_record(mrb_state *mrb, mrb_irep *irep, unsigned char* bin, uint32_t * } static size_t -mrb_write_eof(mrb_state *mrb, unsigned char *bin) +mrb_write_eof(mrb_state *mrb, uint8_t *bin) { struct rite_binary_footer footer; @@ -284,7 +284,7 @@ mrb_write_eof(mrb_state *mrb, unsigned char *bin) static int -mrb_write_section_irep_header(mrb_state *mrb, uint32_t section_size, uint16_t nirep, uint16_t sirep, unsigned char *bin) +mrb_write_section_irep_header(mrb_state *mrb, uint32_t section_size, uint16_t nirep, uint16_t sirep, uint8_t *bin) { struct rite_section_irep_header *header = (struct rite_section_irep_header*)bin; @@ -298,11 +298,11 @@ mrb_write_section_irep_header(mrb_state *mrb, uint32_t section_size, uint16_t ni } static int -mrb_write_section_irep(mrb_state *mrb, int start_index, unsigned char *bin) +mrb_write_section_irep(mrb_state *mrb, int start_index, uint8_t *bin) { int result, irep_no; uint32_t section_size = 0, rlen = 0; /* size of irep record */ - unsigned char *cur = bin; + uint8_t *cur = bin; if (mrb == NULL || start_index < 0 || start_index >= mrb->irep_len || bin == NULL) { return MRB_DUMP_INVALID_ARGUMENT; @@ -326,7 +326,7 @@ mrb_write_section_irep(mrb_state *mrb, int start_index, unsigned char *bin) } static int -write_rite_binary_header(mrb_state *mrb, uint32_t binary_size, unsigned char* bin) +write_rite_binary_header(mrb_state *mrb, uint32_t binary_size, uint8_t* bin) { struct rite_binary_header *header = (struct rite_binary_header*)bin; uint16_t crc; @@ -346,10 +346,10 @@ write_rite_binary_header(mrb_state *mrb, uint32_t binary_size, unsigned char* bi } static int -mrb_dump_irep(mrb_state *mrb, int start_index, unsigned char **bin, uint32_t *bin_size) +mrb_dump_irep(mrb_state *mrb, int start_index, uint8_t **bin, uint32_t *bin_size) { int result = MRB_DUMP_OK, irep_no, section_irep_size; - unsigned char *cur = NULL; + uint8_t *cur = NULL; if (mrb == NULL || start_index < 0 || start_index >= mrb->irep_len) { *bin = NULL; @@ -362,7 +362,7 @@ mrb_dump_irep(mrb_state *mrb, int start_index, unsigned char **bin, uint32_t *bi } *bin_size += sizeof(struct rite_binary_header) + section_irep_size + sizeof(struct rite_binary_footer); - cur = *bin = (unsigned char *)mrb_malloc(mrb, *bin_size); + cur = *bin = (uint8_t *)mrb_malloc(mrb, *bin_size); if(cur == NULL) { goto error_exit; } @@ -393,7 +393,7 @@ error_exit: int mrb_dump_irep_binary(mrb_state *mrb, int start_index, FILE* fp) { - unsigned char *bin = NULL; + uint8_t *bin = NULL; uint32_t bin_size = 0; int result; @@ -413,7 +413,7 @@ mrb_dump_irep_binary(mrb_state *mrb, int start_index, FILE* fp) int mrb_dump_irep_cfunc(mrb_state *mrb, int start_index, FILE *fp, const char *initname) { - unsigned char *bin = NULL; + uint8_t *bin = NULL; uint32_t bin_size = 0, bin_idx = 0; int result; @@ -423,10 +423,10 @@ mrb_dump_irep_cfunc(mrb_state *mrb, int start_index, FILE *fp, const char *initn result = mrb_dump_irep(mrb, start_index, &bin, &bin_size); if (result == MRB_DUMP_OK) { - fprintf(fp, "const unsigned char %s[] = {", initname); + fprintf(fp, "const uint8_t %s[] = {", initname); while (bin_idx < bin_size) { if (bin_idx % 16 == 0 ) fputs("\n", fp); - fprintf(fp, "0x%02x,", (unsigned char)bin[bin_idx++]); + fprintf(fp, "0x%02x,", bin[bin_idx++]); } fputs("\n};\n", fp); } diff --git a/src/load.c b/src/load.c index 82b6b7b6f..30a987492 100644 --- a/src/load.c +++ b/src/load.c @@ -20,11 +20,11 @@ offset_crc_body() } static int -read_rite_irep_record(mrb_state *mrb, const unsigned char *bin, uint32_t *len) +read_rite_irep_record(mrb_state *mrb, const uint8_t *bin, uint32_t *len) { int i, ret = MRB_DUMP_OK; - char *buf; - const unsigned char *src = bin; + 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; @@ -32,8 +32,8 @@ read_rite_irep_record(mrb_state *mrb, const unsigned char *bin, uint32_t *len) int ai = mrb_gc_arena_save(mrb); mrb_irep *irep = mrb_add_irep(mrb); - buf = (char *)mrb_malloc(mrb, buf_size); - if (buf == NULL) { + char_buf = (char *)mrb_malloc(mrb, buf_size); + if (char_buf == NULL) { ret = MRB_DUMP_GENERAL_FAILURE; goto error_exit; } @@ -80,30 +80,30 @@ read_rite_irep_record(mrb_state *mrb, const unsigned char *bin, uint32_t *len) pool_data_len = bin_to_uint16(src); //pool data length src += sizeof(uint16_t); if (pool_data_len > buf_size - 1) { - mrb_free(mrb, buf); + mrb_free(mrb, char_buf); buf_size = pool_data_len + 1; - buf = (char *)mrb_malloc(mrb, buf_size); - if (buf == NULL) { + char_buf = (char *)mrb_malloc(mrb, buf_size); + if (char_buf == NULL) { ret = MRB_DUMP_GENERAL_FAILURE; goto error_exit; } } - memcpy(buf, src, pool_data_len); + memcpy(char_buf, src, pool_data_len); src += pool_data_len; - buf[pool_data_len] = '\0'; + char_buf[pool_data_len] = '\0'; switch (tt) { //pool data case MRB_TT_FIXNUM: - fix_num = str_to_mrb_int(buf); + fix_num = str_to_mrb_int(char_buf); irep->pool[i] = mrb_fixnum_value(fix_num); break; case MRB_TT_FLOAT: - f = str_to_mrb_float(buf); + f = str_to_mrb_float(char_buf); irep->pool[i] = mrb_float_value(f); break; case MRB_TT_STRING: - irep->pool[i] = mrb_str_new(mrb, buf, pool_data_len); + irep->pool[i] = mrb_str_new(mrb, char_buf, pool_data_len); break; default: @@ -139,29 +139,29 @@ read_rite_irep_record(mrb_state *mrb, const unsigned char *bin, uint32_t *len) } if (snl > buf_size - 1) { - mrb_free(mrb, buf); + mrb_free(mrb, char_buf); buf_size = snl + 1; - buf = (char *)mrb_malloc(mrb, buf_size); - if (buf == NULL) { + char_buf = (char *)mrb_malloc(mrb, buf_size); + if (char_buf == NULL) { ret = MRB_DUMP_GENERAL_FAILURE; goto error_exit; } } - memcpy(buf, src, snl); //symbol name + memcpy(char_buf, src, snl); //symbol name src += snl; - buf[snl] = '\0'; - irep->syms[i] = mrb_intern2(mrb, buf, snl); + char_buf[snl] = '\0'; + irep->syms[i] = mrb_intern2(mrb, char_buf, snl); } } *len = src - bin; error_exit: - mrb_free(mrb, buf); + mrb_free(mrb, char_buf); return ret; } static int -read_rite_section_irep(mrb_state *mrb, const unsigned char *bin) +read_rite_section_irep(mrb_state *mrb, const uint8_t *bin) { int n, i, result = MRB_DUMP_OK; uint32_t len, sirep; @@ -204,7 +204,7 @@ error_exit: } static int -read_rite_binary_header(const unsigned char *bin, uint32_t *bin_size, uint16_t *crc) +read_rite_binary_header(const uint8_t *bin, uint32_t *bin_size, uint16_t *crc) { const struct rite_binary_header *header = (const struct rite_binary_header *)bin; @@ -223,7 +223,7 @@ read_rite_binary_header(const unsigned char *bin, uint32_t *bin_size, uint16_t * } int -mrb_read_irep(mrb_state *mrb, const unsigned char *bin) +mrb_read_irep(mrb_state *mrb, const uint8_t *bin) { int total_nirep = 0, result = MRB_DUMP_OK; const struct rite_section_header *section_header; @@ -268,7 +268,7 @@ irep_error(mrb_state *mrb, const char *msg) } mrb_value -mrb_load_irep(mrb_state *mrb, const unsigned char *bin) +mrb_load_irep(mrb_state *mrb, const uint8_t *bin) { int n; @@ -288,7 +288,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) int n, i, result = MRB_DUMP_OK; uint16_t sirep, nirep; uint32_t len, buf_size; - unsigned char *buf = NULL; + uint8_t *buf = NULL; const int record_header_size = 1 + 4; struct rite_section_irep_header header; @@ -298,13 +298,13 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp) nirep = bin_to_uint16(header.nirep); buf_size = record_header_size; - buf = mrb_malloc(mrb, buf_size); + buf = (uint8_t *)mrb_malloc(mrb, buf_size); //Read Binary Data Section for (n = 0, i = sirep; n < nirep; n++, i++) { fread(buf, record_header_size, 1, fp); buf_size = bin_to_uint32(&buf[0]); - buf = mrb_realloc(mrb, buf, buf_size); + buf = (uint8_t *)mrb_realloc(mrb, buf, buf_size); fread(&buf[record_header_size], buf_size - record_header_size, 1, fp); result = read_rite_irep_record(mrb, buf, &len); if (result != MRB_DUMP_OK) @@ -337,7 +337,7 @@ int mrb_read_irep_file(mrb_state *mrb, FILE* fp) { int total_nirep = 0, result = MRB_DUMP_OK; - unsigned char *buf; + uint8_t *buf; uint16_t crc, crcwk = 0; uint32_t bin_size = 0, buf_size = 0, section_size = 0; size_t nbytes; diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index f077e6d51..069a76ac9 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -4,7 +4,7 @@ #include "mruby/string.h" #include "mruby/proc.h" -extern const unsigned char mrbtest_irep[]; +extern const uint8_t mrbtest_irep[]; void mrbgemtest_init(mrb_state* mrb); |
