Commit 709c120d authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #734 from monaka/pr-error-check-inprovement-in-cdump-and-dump

Error check inprovements in cdump and dump
parents 79aa7179 85bdd634
...@@ -23,6 +23,9 @@ int mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); ...@@ -23,6 +23,9 @@ int mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
/* error code */ /* error code */
#define MRB_CDUMP_OK 0 #define MRB_CDUMP_OK 0
#define MRB_CDUMP_GENERAL_FAILURE -1 #define MRB_CDUMP_GENERAL_FAILURE -1
#define MRB_CDUMP_WRITE_FAULT -2
#define MRB_CDUMP_INVALID_IREP -6
#define MRB_CDUMP_INVALID_ARGUMENT -7
#if defined(__cplusplus) #if defined(__cplusplus)
} /* extern "C" { */ } /* extern "C" { */
......
...@@ -23,7 +23,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f) ...@@ -23,7 +23,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f)
mrb_irep *irep = mrb->irep[irep_no]; mrb_irep *irep = mrb->irep[irep_no];
if (irep == NULL) if (irep == NULL)
return -1; return MRB_CDUMP_INVALID_IREP;
/* dump isec struct*/ /* dump isec struct*/
if (irep->ilen > 0) { if (irep->ilen > 0) {
...@@ -34,7 +34,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f) ...@@ -34,7 +34,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f)
SOURCE_CODE0 (""); SOURCE_CODE0 ("");
} }
return 0; return MRB_CDUMP_OK;
} }
static size_t static size_t
...@@ -104,7 +104,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f) ...@@ -104,7 +104,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
size_t buf_len, str_len; size_t buf_len, str_len;
if (irep == NULL) if (irep == NULL)
return -1; return MRB_CDUMP_INVALID_IREP;
buf_len = MRB_CDUMP_LINE_LEN; buf_len = MRB_CDUMP_LINE_LEN;
if ((buf = (char *)mrb_malloc(mrb, buf_len)) == NULL) { if ((buf = (char *)mrb_malloc(mrb, buf_len)) == NULL) {
...@@ -176,9 +176,10 @@ int ...@@ -176,9 +176,10 @@ int
mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
{ {
int irep_no; int irep_no;
int error;
if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL) if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL)
return -1; return MRB_CDUMP_INVALID_ARGUMENT;
SOURCE_CODE0("#include \"mruby.h\""); SOURCE_CODE0("#include \"mruby.h\"");
SOURCE_CODE0("#include \"mruby/irep.h\""); SOURCE_CODE0("#include \"mruby/irep.h\"");
...@@ -187,8 +188,9 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) ...@@ -187,8 +188,9 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
SOURCE_CODE0(""); SOURCE_CODE0("");
for (irep_no=n; irep_no<mrb->irep_len; irep_no++) { for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
if (make_cdump_isec(mrb, irep_no, f) != 0) error = make_cdump_isec(mrb, irep_no, f);
return -1; if (error != MRB_CDUMP_OK)
return error;
} }
SOURCE_CODE0("void"); SOURCE_CODE0("void");
...@@ -200,12 +202,13 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) ...@@ -200,12 +202,13 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
SOURCE_CODE0(" mrb_irep *irep;"); SOURCE_CODE0(" mrb_irep *irep;");
SOURCE_CODE0(""); SOURCE_CODE0("");
for (irep_no=n; irep_no<mrb->irep_len; irep_no++) { for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
if (make_cdump_irep(mrb, irep_no, f) != 0) error = make_cdump_irep(mrb, irep_no, f);
return -1; if (error != MRB_CDUMP_OK)
return error;
} }
SOURCE_CODE0(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); SOURCE_CODE0(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));");
SOURCE_CODE0("}"); SOURCE_CODE0("}");
return 0; return MRB_CDUMP_OK;
} }
...@@ -690,7 +690,7 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin) ...@@ -690,7 +690,7 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin)
for (irep_no=top; irep_no<mrb->irep_len; irep_no++) { for (irep_no=top; irep_no<mrb->irep_len; irep_no++) {
rc = write_irep_record(mrb, irep_no, bin, &rlen, DUMP_TYPE_BIN); rc = write_irep_record(mrb, irep_no, bin, &rlen, DUMP_TYPE_BIN);
if (rc != 0) if (rc != MRB_DUMP_OK)
return rc; return rc;
bin += (rlen + DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, DUMP_TYPE_BIN)); bin += (rlen + DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, DUMP_TYPE_BIN));
...@@ -719,7 +719,7 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp) ...@@ -719,7 +719,7 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp)
for (irep_no=top; irep_no<mrb->irep_len; irep_no++) { for (irep_no=top; irep_no<mrb->irep_len; irep_no++) {
rc = dump_irep_record(mrb, irep_no, fp, &rlen); rc = dump_irep_record(mrb, irep_no, fp, &rlen);
if (rc != 0) if (rc != MRB_DUMP_OK)
return rc; return rc;
rbds += rlen; rbds += rlen;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment