Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
eab894e5
Commit
eab894e5
authored
Jan 08, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #710 from monaka/pr-strict-error-checking
Strict runtime error checking
parents
2c6d34f1
d5b8dc54
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
37 deletions
+97
-37
include/mruby/dump.h
include/mruby/dump.h
+5
-1
src/dump.c
src/dump.c
+56
-20
src/load.c
src/load.c
+36
-16
No files found.
include/mruby/dump.h
View file @
eab894e5
...
@@ -28,7 +28,11 @@ int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
...
@@ -28,7 +28,11 @@ int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
#define DUMP_TYPE_BIN 1
#define DUMP_TYPE_BIN 1
#define DUMP_TYPE_HEX 2
#define DUMP_TYPE_HEX 2
/* dump/load error code */
/* dump/load error code
*
* NOTE: MRB_DUMP_GENERAL_FAILURE is caused by
* unspecified issues like malloc failed.
*/
#define MRB_DUMP_OK 0
#define MRB_DUMP_OK 0
#define MRB_DUMP_GENERAL_FAILURE -1
#define MRB_DUMP_GENERAL_FAILURE -1
#define MRB_DUMP_WRITE_FAULT -2
#define MRB_DUMP_WRITE_FAULT -2
...
...
src/dump.c
View file @
eab894e5
...
@@ -351,10 +351,14 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -351,10 +351,14 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
char
*
char_buf
;
char
*
char_buf
;
uint16_t
buf_size
=
0
;
uint16_t
buf_size
=
0
;
uint16_t
len
=
0
;
uint16_t
len
=
0
;
int
result
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
if
((
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
buf
+=
uint32_dump
((
uint32_t
)
irep
->
plen
,
buf
,
type
);
/* number of pool */
buf
+=
uint32_dump
((
uint32_t
)
irep
->
plen
,
buf
,
type
);
/* number of pool */
...
@@ -376,8 +380,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -376,8 +380,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
len
=
str_dump_len
(
RSTRING_PTR
(
str
),
RSTRING_LEN
(
str
),
type
);
len
=
str_dump_len
(
RSTRING_PTR
(
str
),
RSTRING_LEN
(
str
),
type
);
if
(
len
>
buf_size
-
1
)
{
if
(
len
>
buf_size
-
1
)
{
buf_size
=
len
+
1
;
buf_size
=
len
+
1
;
if
((
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
memset
(
char_buf
,
0
,
buf_size
);
memset
(
char_buf
,
0
,
buf_size
);
}
}
str_dump
(
RSTRING_PTR
(
str
),
char_buf
,
RSTRING_LEN
(
str
),
type
);
str_dump
(
RSTRING_PTR
(
str
),
char_buf
,
RSTRING_LEN
(
str
),
type
);
...
@@ -389,8 +396,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -389,8 +396,11 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
len
=
str_dump_len
(
RSTRING_PTR
(
str
),
RSTRING_LEN
(
str
),
type
);
len
=
str_dump_len
(
RSTRING_PTR
(
str
),
RSTRING_LEN
(
str
),
type
);
if
(
len
>
buf_size
-
1
)
{
if
(
len
>
buf_size
-
1
)
{
buf_size
=
len
+
1
;
buf_size
=
len
+
1
;
if
((
char_buf
=
mrb_realloc
(
mrb
,
char_buf
,
buf_size
))
==
NULL
)
char_buf
=
mrb_realloc
(
mrb
,
char_buf
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
memset
(
char_buf
,
0
,
buf_size
);
memset
(
char_buf
,
0
,
buf_size
);
}
}
str_dump
(
RSTRING_PTR
(
str
),
char_buf
,
RSTRING_LEN
(
str
),
type
);
str_dump
(
RSTRING_PTR
(
str
),
char_buf
,
RSTRING_LEN
(
str
),
type
);
...
@@ -408,9 +418,10 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -408,9 +418,10 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
buf
+=
len
;
buf
+=
len
;
}
}
result
=
(
int
)(
buf
-
buf_top
);
error_exit:
error_exit:
mrb_free
(
mrb
,
char_buf
);
mrb_free
(
mrb
,
char_buf
);
return
(
int
)(
buf
-
buf_top
)
;
return
result
;
}
}
static
int
static
int
...
@@ -422,7 +433,8 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -422,7 +433,8 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
uint16_t
buf_size
=
0
;
uint16_t
buf_size
=
0
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
if
((
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
);
if
(
char_buf
==
NULL
)
goto
error_exit
;
goto
error_exit
;
buf
+=
uint32_dump
((
uint32_t
)
irep
->
slen
,
buf
,
type
);
/* number of symbol */
buf
+=
uint32_dump
((
uint32_t
)
irep
->
slen
,
buf
,
type
);
/* number of symbol */
...
@@ -438,7 +450,8 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
...
@@ -438,7 +450,8 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
nlen
=
str_dump_len
((
char
*
)
name
,
len
,
type
);
nlen
=
str_dump_len
((
char
*
)
name
,
len
,
type
);
if
(
nlen
>
buf_size
-
1
)
{
if
(
nlen
>
buf_size
-
1
)
{
buf_size
=
nlen
+
1
;
buf_size
=
nlen
+
1
;
if
((
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
);
if
(
char_buf
==
NULL
)
goto
error_exit
;
goto
error_exit
;
}
}
memset
(
char_buf
,
0
,
buf_size
);
memset
(
char_buf
,
0
,
buf_size
);
...
@@ -464,6 +477,7 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
...
@@ -464,6 +477,7 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
char
*
buf
,
*
buf_top
;
char
*
buf
,
*
buf_top
;
uint32_t
buf_size
;
uint32_t
buf_size
;
int
type
=
DUMP_TYPE_BIN
;
int
type
=
DUMP_TYPE_BIN
;
int
result
;
switch
(
section
)
{
switch
(
section
)
{
case
DUMP_IREP_HEADER
:
buf_size
=
get_irep_header_size
(
mrb
,
irep
,
type
);
break
;
case
DUMP_IREP_HEADER
:
buf_size
=
get_irep_header_size
(
mrb
,
irep
,
type
);
break
;
...
@@ -473,24 +487,40 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
...
@@ -473,24 +487,40 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
default:
return
MRB_DUMP_GENERAL_FAILURE
;
default:
return
MRB_DUMP_GENERAL_FAILURE
;
}
}
if
((
buf
=
(
char
*
)
mrb_calloc
(
mrb
,
1
,
buf_size
))
==
NULL
)
buf
=
(
char
*
)
mrb_calloc
(
mrb
,
1
,
buf_size
);
if
(
buf
==
NULL
)
return
MRB_DUMP_GENERAL_FAILURE
;
return
MRB_DUMP_GENERAL_FAILURE
;
buf_top
=
buf
;
buf_top
=
buf
;
switch
(
section
)
{
switch
(
section
)
{
case
DUMP_IREP_HEADER
:
buf
+=
write_irep_header
(
mrb
,
irep
,
buf
,
type
);
break
;
case
DUMP_IREP_HEADER
:
case
DUMP_ISEQ_BLOCK
:
buf
+=
write_iseq_block
(
mrb
,
irep
,
buf
,
type
);
break
;
result
=
write_irep_header
(
mrb
,
irep
,
buf
,
type
);
case
DUMP_POOL_BLOCK
:
buf
+=
write_pool_block
(
mrb
,
irep
,
buf
,
type
);
break
;
break
;
case
DUMP_SYMS_BLOCK
:
buf
+=
write_syms_block
(
mrb
,
irep
,
buf
,
type
);
break
;
case
DUMP_ISEQ_BLOCK
:
default:
break
;
result
=
write_iseq_block
(
mrb
,
irep
,
buf
,
type
);
break
;
case
DUMP_POOL_BLOCK
:
result
=
write_pool_block
(
mrb
,
irep
,
buf
,
type
);
break
;
case
DUMP_SYMS_BLOCK
:
result
=
write_syms_block
(
mrb
,
irep
,
buf
,
type
);
break
;
default:
break
;
/* Already checked above. */
}
if
(
result
<
0
)
{
goto
error_exit
;
}
}
buf
+=
result
;
*
crc
=
calc_crc_16_ccitt
((
unsigned
char
*
)
buf_top
,
(
int
)(
buf
-
buf_top
));
*
crc
=
calc_crc_16_ccitt
((
unsigned
char
*
)
buf_top
,
(
int
)(
buf
-
buf_top
));
mrb_free
(
mrb
,
buf_top
);
mrb_free
(
mrb
,
buf_top
);
return
MRB_DUMP_OK
;
result
=
MRB_DUMP_OK
;
error_exit:
return
result
;
}
}
static
uint16_t
static
uint16_t
...
@@ -597,7 +627,8 @@ write_irep_record(mrb_state *mrb, int irep_no, char* bin, uint32_t *rlen, int ty
...
@@ -597,7 +627,8 @@ write_irep_record(mrb_state *mrb, int irep_no, char* bin, uint32_t *rlen, int ty
default:
break
;
default:
break
;
}
}
if
((
rc
=
calc_crc_section
(
mrb
,
irep
,
&
crc
,
section
))
!=
0
)
rc
=
calc_crc_section
(
mrb
,
irep
,
&
crc
,
section
);
if
(
rc
!=
MRB_DUMP_OK
)
return
rc
;
return
rc
;
bin
+=
uint16_dump
(
crc
,
bin
,
type
);
/* crc */
bin
+=
uint16_dump
(
crc
,
bin
,
type
);
/* crc */
...
@@ -622,10 +653,12 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen)
...
@@ -622,10 +653,12 @@ dump_irep_record(mrb_state *mrb, int irep_no, FILE* fp, uint32_t *rlen)
if
(
irep_record_size
==
0
)
if
(
irep_record_size
==
0
)
return
MRB_DUMP_GENERAL_FAILURE
;
return
MRB_DUMP_GENERAL_FAILURE
;
if
((
buf
=
(
char
*
)
mrb_calloc
(
mrb
,
1
,
irep_record_size
))
==
NULL
)
buf
=
(
char
*
)
mrb_calloc
(
mrb
,
1
,
irep_record_size
);
if
(
buf
==
NULL
)
return
MRB_DUMP_GENERAL_FAILURE
;
return
MRB_DUMP_GENERAL_FAILURE
;
if
((
rc
=
write_irep_record
(
mrb
,
irep_no
,
buf
,
rlen
,
DUMP_TYPE_HEX
))
!=
MRB_DUMP_OK
)
{
rc
=
write_irep_record
(
mrb
,
irep_no
,
buf
,
rlen
,
DUMP_TYPE_HEX
);
if
(
rc
!=
MRB_DUMP_OK
)
{
rc
=
MRB_DUMP_GENERAL_FAILURE
;
rc
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -655,7 +688,8 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin)
...
@@ -655,7 +688,8 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin)
bin
+=
sizeof
(
rite_binary_header
)
+
MRB_DUMP_SIZE_OF_SHORT
/* crc */
;
bin
+=
sizeof
(
rite_binary_header
)
+
MRB_DUMP_SIZE_OF_SHORT
/* crc */
;
for
(
irep_no
=
top
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
{
for
(
irep_no
=
top
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
{
if
((
rc
=
write_irep_record
(
mrb
,
irep_no
,
bin
,
&
rlen
,
DUMP_TYPE_BIN
))
!=
0
)
rc
=
write_irep_record
(
mrb
,
irep_no
,
bin
,
&
rlen
,
DUMP_TYPE_BIN
);
if
(
rc
!=
0
)
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
));
...
@@ -683,7 +717,8 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp)
...
@@ -683,7 +717,8 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp)
return
MRB_DUMP_WRITE_FAULT
;
return
MRB_DUMP_WRITE_FAULT
;
for
(
irep_no
=
top
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
{
for
(
irep_no
=
top
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
{
if
((
rc
=
dump_irep_record
(
mrb
,
irep_no
,
fp
,
&
rlen
))
!=
0
)
rc
=
dump_irep_record
(
mrb
,
irep_no
,
fp
,
&
rlen
);
if
(
rc
!=
0
)
return
rc
;
return
rc
;
rbds
+=
rlen
;
rbds
+=
rlen
;
...
@@ -707,14 +742,15 @@ mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
...
@@ -707,14 +742,15 @@ mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
int
buf_idx
=
0
;
int
buf_idx
=
0
;
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_DUMP_INVALID_ARGUMENT
;
buf_size
=
sizeof
(
rite_binary_header
)
+
MRB_DUMP_SIZE_OF_SHORT
/* crc */
;
buf_size
=
sizeof
(
rite_binary_header
)
+
MRB_DUMP_SIZE_OF_SHORT
/* crc */
;
for
(
irep_no
=
n
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
for
(
irep_no
=
n
;
irep_no
<
mrb
->
irep_len
;
irep_no
++
)
buf_size
+=
get_irep_record_size
(
mrb
,
irep_no
,
DUMP_TYPE_BIN
);
buf_size
+=
get_irep_record_size
(
mrb
,
irep_no
,
DUMP_TYPE_BIN
);
buf_size
+=
MRB_DUMP_SIZE_OF_LONG
;
/* end of file */
buf_size
+=
MRB_DUMP_SIZE_OF_LONG
;
/* end of file */
if
((
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
))
==
NULL
)
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
);
if
(
buf
==
NULL
)
return
MRB_DUMP_GENERAL_FAILURE
;
return
MRB_DUMP_GENERAL_FAILURE
;
rc
=
mrb_write_irep
(
mrb
,
n
,
buf
);
rc
=
mrb_write_irep
(
mrb
,
n
,
buf
);
...
...
src/load.c
View file @
eab894e5
...
@@ -142,10 +142,14 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
...
@@ -142,10 +142,14 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
unsigned
char
*
pStart
;
unsigned
char
*
pStart
;
char
*
char_buf
;
char
*
char_buf
;
uint16_t
buf_size
=
0
;
uint16_t
buf_size
=
0
;
int
result
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
buf_size
=
MRB_DUMP_DEFAULT_STR_LEN
;
if
((
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
pStart
=
dst
;
pStart
=
dst
;
...
@@ -193,9 +197,12 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
...
@@ -193,9 +197,12 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
if
(
pdl
>
buf_size
-
1
)
{
if
(
pdl
>
buf_size
-
1
)
{
buf_size
=
pdl
+
1
;
buf_size
=
pdl
+
1
;
if
((
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
}
memset
(
char_buf
,
'\0'
,
buf_size
);
memset
(
char_buf
,
'\0'
,
buf_size
);
rite_fgets
(
rfp
,
(
unsigned
char
*
)
char_buf
,
pdl
,
FALSE
);
//pool
rite_fgets
(
rfp
,
(
unsigned
char
*
)
char_buf
,
pdl
,
FALSE
);
//pool
hex_to_str
(
char_buf
,
(
char
*
)(
dst
+
MRB_DUMP_SIZE_OF_SHORT
),
&
clen
);
hex_to_str
(
char_buf
,
(
char
*
)(
dst
+
MRB_DUMP_SIZE_OF_SHORT
),
&
clen
);
...
@@ -220,9 +227,12 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
...
@@ -220,9 +227,12 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
if
(
snl
>
buf_size
-
1
)
{
if
(
snl
>
buf_size
-
1
)
{
buf_size
=
snl
+
1
;
buf_size
=
snl
+
1
;
if
((
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
))
==
NULL
)
char_buf
=
(
char
*
)
mrb_realloc
(
mrb
,
char_buf
,
buf_size
);
if
(
char_buf
==
NULL
)
{
result
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
}
memset
(
char_buf
,
'\0'
,
buf_size
);
memset
(
char_buf
,
'\0'
,
buf_size
);
rite_fgets
(
rfp
,
(
unsigned
char
*
)
char_buf
,
snl
,
FALSE
);
//symbol name
rite_fgets
(
rfp
,
(
unsigned
char
*
)
char_buf
,
snl
,
FALSE
);
//symbol name
hex_to_str
(
char_buf
,
(
char
*
)(
dst
+
MRB_DUMP_SIZE_OF_SHORT
),
&
clen
);
hex_to_str
(
char_buf
,
(
char
*
)(
dst
+
MRB_DUMP_SIZE_OF_SHORT
),
&
clen
);
...
@@ -234,10 +244,11 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
...
@@ -234,10 +244,11 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
*
len
=
dst
-
pStart
;
*
len
=
dst
-
pStart
;
result
=
MRB_DUMP_OK
;
error_exit:
error_exit:
mrb_free
(
mrb
,
char_buf
);
mrb_free
(
mrb
,
char_buf
);
return
MRB_DUMP_OK
;
return
result
;
}
}
int
int
...
@@ -258,11 +269,13 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
...
@@ -258,11 +269,13 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
rfp
=
&
ritefp
;
rfp
=
&
ritefp
;
//Read File Header Section
//Read File Header Section
if
((
ret
=
load_rite_header
(
fp
,
&
bin_header
,
hcrc
))
!=
MRB_DUMP_OK
)
ret
=
load_rite_header
(
fp
,
&
bin_header
,
hcrc
);
if
(
ret
!=
MRB_DUMP_OK
)
return
ret
;
return
ret
;
len
=
sizeof
(
rite_binary_header
)
+
bin_to_uint32
(
bin_header
.
rbds
);
len
=
sizeof
(
rite_binary_header
)
+
bin_to_uint32
(
bin_header
.
rbds
);
if
((
rite_dst
=
(
unsigned
char
*
)
mrb_malloc
(
mrb
,
len
))
==
NULL
)
rite_dst
=
(
unsigned
char
*
)
mrb_malloc
(
mrb
,
len
);
if
(
rite_dst
==
NULL
)
return
MRB_DUMP_GENERAL_FAILURE
;
return
MRB_DUMP_GENERAL_FAILURE
;
dst
=
rite_dst
;
dst
=
rite_dst
;
...
@@ -276,7 +289,8 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
...
@@ -276,7 +289,8 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
for
(
i
=
0
;
i
<
len
;
i
++
)
{
rite_fgets
(
rfp
,
hex8
,
sizeof
(
hex8
),
TRUE
);
//record len
rite_fgets
(
rfp
,
hex8
,
sizeof
(
hex8
),
TRUE
);
//record len
dst
+=
hex_to_bin32
(
dst
,
hex8
);
dst
+=
hex_to_bin32
(
dst
,
hex8
);
if
((
ret
=
load_rite_irep_record
(
mrb
,
rfp
,
dst
,
&
rlen
))
!=
MRB_DUMP_OK
)
//irep info
ret
=
load_rite_irep_record
(
mrb
,
rfp
,
dst
,
&
rlen
);
if
(
ret
!=
MRB_DUMP_OK
)
//irep info
goto
error_exit
;
goto
error_exit
;
dst
+=
rlen
;
dst
+=
rlen
;
}
}
...
@@ -334,7 +348,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -334,7 +348,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
recordStart
=
src
;
recordStart
=
src
;
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
);
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
);
if
(
buf
==
NULL
)
{
if
(
buf
==
NULL
)
{
ret
=
MRB_DUMP_
INVALID_IREP
;
ret
=
MRB_DUMP_
GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -360,7 +374,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -360,7 +374,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
irep
->
ilen
=
bin_to_uint32
(
src
);
//iseq length
irep
->
ilen
=
bin_to_uint32
(
src
);
//iseq length
src
+=
MRB_DUMP_SIZE_OF_LONG
;
src
+=
MRB_DUMP_SIZE_OF_LONG
;
if
(
irep
->
ilen
>
0
)
{
if
(
irep
->
ilen
>
0
)
{
if
((
irep
->
iseq
=
(
mrb_code
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_code
)
*
irep
->
ilen
))
==
NULL
)
{
irep
->
iseq
=
(
mrb_code
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_code
)
*
irep
->
ilen
);
if
(
irep
->
iseq
==
NULL
)
{
ret
=
MRB_DUMP_GENERAL_FAILURE
;
ret
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -383,7 +398,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -383,7 +398,7 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
if
(
plen
>
0
)
{
if
(
plen
>
0
)
{
irep
->
pool
=
(
mrb_value
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_value
)
*
plen
);
irep
->
pool
=
(
mrb_value
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_value
)
*
plen
);
if
(
irep
->
pool
==
NULL
)
{
if
(
irep
->
pool
==
NULL
)
{
ret
=
MRB_DUMP_
INVALID_IREP
;
ret
=
MRB_DUMP_
GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -395,7 +410,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -395,7 +410,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
if
(
pdl
>
bufsize
-
1
)
{
if
(
pdl
>
bufsize
-
1
)
{
mrb_free
(
mrb
,
buf
);
mrb_free
(
mrb
,
buf
);
bufsize
=
pdl
+
1
;
bufsize
=
pdl
+
1
;
if
((
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
))
==
NULL
)
{
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
);
if
(
buf
==
NULL
)
{
ret
=
MRB_DUMP_GENERAL_FAILURE
;
ret
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -446,8 +462,9 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -446,8 +462,9 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
irep
->
slen
=
bin_to_uint32
(
src
);
//syms length
irep
->
slen
=
bin_to_uint32
(
src
);
//syms length
src
+=
MRB_DUMP_SIZE_OF_LONG
;
src
+=
MRB_DUMP_SIZE_OF_LONG
;
if
(
irep
->
slen
>
0
)
{
if
(
irep
->
slen
>
0
)
{
if
((
irep
->
syms
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
*
irep
->
slen
))
==
NULL
)
{
irep
->
syms
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
)
*
irep
->
slen
);
ret
=
MRB_DUMP_INVALID_IREP
;
if
(
irep
->
syms
==
NULL
)
{
ret
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -467,7 +484,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
...
@@ -467,7 +484,8 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, uint32_t* len)
if
(
snl
>
bufsize
-
1
)
{
if
(
snl
>
bufsize
-
1
)
{
mrb_free
(
mrb
,
buf
);
mrb_free
(
mrb
,
buf
);
bufsize
=
snl
+
1
;
bufsize
=
snl
+
1
;
if
((
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
))
==
NULL
)
{
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
bufsize
);
if
(
buf
==
NULL
)
{
ret
=
MRB_DUMP_GENERAL_FAILURE
;
ret
=
MRB_DUMP_GENERAL_FAILURE
;
goto
error_exit
;
goto
error_exit
;
}
}
...
@@ -507,7 +525,8 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
...
@@ -507,7 +525,8 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
sirep
=
mrb
->
irep_len
;
sirep
=
mrb
->
irep_len
;
//Read File Header Section
//Read File Header Section
if
((
nirep
=
read_rite_header
(
mrb
,
src
,
&
bin_header
))
<
0
)
nirep
=
read_rite_header
(
mrb
,
src
,
&
bin_header
);
if
(
nirep
<
0
)
return
nirep
;
return
nirep
;
src
+=
sizeof
(
bin_header
)
+
MRB_DUMP_SIZE_OF_SHORT
;
//header + crc
src
+=
sizeof
(
bin_header
)
+
MRB_DUMP_SIZE_OF_SHORT
;
//header + crc
...
@@ -515,7 +534,8 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
...
@@ -515,7 +534,8 @@ mrb_read_irep(mrb_state *mrb, const char *bin)
//Read Binary Data Section
//Read Binary Data Section
for
(
n
=
0
,
i
=
sirep
;
n
<
nirep
;
n
++
,
i
++
)
{
for
(
n
=
0
,
i
=
sirep
;
n
<
nirep
;
n
++
,
i
++
)
{
src
+=
MRB_DUMP_SIZE_OF_LONG
;
//record ren
src
+=
MRB_DUMP_SIZE_OF_LONG
;
//record ren
if
((
ret
=
read_rite_irep_record
(
mrb
,
src
,
&
len
))
!=
MRB_DUMP_OK
)
ret
=
read_rite_irep_record
(
mrb
,
src
,
&
len
);
if
(
ret
!=
MRB_DUMP_OK
)
goto
error_exit
;
goto
error_exit
;
src
+=
len
;
src
+=
len
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment