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
3f70edbd
Commit
3f70edbd
authored
Sep 05, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support native byteorder in mrb files; ref 3492be
parent
5b235a8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
29 deletions
+27
-29
src/load.c
src/load.c
+27
-29
No files found.
src/load.c
View file @
3f70edbd
...
...
@@ -80,9 +80,15 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
}
else
{
irep
->
iseq
=
(
mrb_code
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_code
)
*
irep
->
ilen
);
for
(
i
=
0
;
i
<
irep
->
ilen
;
i
++
)
{
irep
->
iseq
[
i
]
=
(
mrb_code
)
bin_to_uint32
(
src
);
/* iseq */
src
+=
sizeof
(
uint32_t
);
if
(
flags
&
FLAG_BYTEORDER_NATIVE
)
{
memcpy
(
irep
->
iseq
,
src
,
sizeof
(
uint32_t
)
*
irep
->
ilen
);
src
+=
sizeof
(
uint32_t
)
*
irep
->
ilen
;
}
else
{
for
(
i
=
0
;
i
<
irep
->
ilen
;
i
++
)
{
irep
->
iseq
[
i
]
=
(
mrb_code
)
bin_to_uint32
(
src
);
/* iseq */
src
+=
sizeof
(
uint32_t
);
}
}
}
}
...
...
@@ -503,27 +509,22 @@ lv_exit:
}
static
int
read_binary_header
(
const
uint8_t
*
bin
,
size_t
*
bin_size
,
uint16_t
*
crc
,
mrb_bool
*
byteorder
)
read_binary_header
(
const
uint8_t
*
bin
,
size_t
*
bin_size
,
uint16_t
*
crc
,
uint8_t
*
flags
)
{
const
struct
rite_binary_header
*
header
=
(
const
struct
rite_binary_header
*
)
bin
;
uint32_t
ident
=
0
;
size_t
i
;
if
(
byteorder
)
*
byteorder
=
FALSE
;
if
(
memcmp
(
header
->
binary_identify
,
RITE_BINARY_IDENTIFIER
,
sizeof
(
header
->
binary_identify
))
!=
0
)
{
if
(
byteorder
)
{
uint32_t
ident
=
0
;
size_t
i
;
for
(
i
=
0
;
i
<
sizeof
(
ident
);
i
++
)
{
ident
<<=
8
;
ident
|=
RITE_BINARY_IDENTIFIER
[
i
];
}
if
(
memcmp
(
header
->
binary_identify
,
&
ident
,
sizeof
(
header
->
binary_identify
))
==
0
)
{
*
byteorder
=
TRUE
;
}
else
{
return
MRB_DUMP_INVALID_FILE_HEADER
;
}
}
/* create native byteorder version of RITE_BINARY_IDENTIFIER */
for
(
i
=
0
;
i
<
sizeof
(
ident
);
i
++
)
{
ident
<<=
8
;
ident
|=
RITE_BINARY_IDENTIFIER
[
i
];
}
if
(
memcmp
(
header
->
binary_identify
,
&
ident
,
sizeof
(
header
->
binary_identify
))
==
0
)
{
*
flags
|=
FLAG_BYTEORDER_NATIVE
;
}
else
if
(
memcmp
(
header
->
binary_identify
,
RITE_BINARY_IDENTIFIER
,
sizeof
(
header
->
binary_identify
))
!=
0
)
{
return
MRB_DUMP_INVALID_FILE_HEADER
;
}
if
(
memcmp
(
header
->
binary_version
,
RITE_BINARY_FORMAT_VER
,
sizeof
(
header
->
binary_version
))
!=
0
)
{
...
...
@@ -547,20 +548,16 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
uint16_t
crc
;
size_t
bin_size
=
0
;
size_t
n
;
mrb_bool
byteorder
;
uint8_t
flags
=
FLAG_SRC_STATIC
;
if
((
mrb
==
NULL
)
||
(
bin
==
NULL
))
{
return
NULL
;
}
result
=
read_binary_header
(
bin
,
&
bin_size
,
&
crc
,
&
byteorder
);
result
=
read_binary_header
(
bin
,
&
bin_size
,
&
crc
,
&
flags
);
if
(
result
!=
MRB_DUMP_OK
)
{
return
NULL
;
}
if
(
byteorder
)
{
flags
|=
FLAG_BYTEORDER_NATIVE
;
}
n
=
offset_crc_body
();
if
(
crc
!=
calc_crc_16_ccitt
(
bin
+
n
,
bin_size
-
n
,
0
))
{
...
...
@@ -738,6 +735,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
const
uint8_t
block_fallback_count
=
4
;
int
i
;
const
size_t
buf_size
=
sizeof
(
struct
rite_binary_header
);
uint8_t
flags
=
FLAG_SRC_MALLOC
;
if
((
mrb
==
NULL
)
||
(
fp
==
NULL
))
{
return
NULL
;
...
...
@@ -749,7 +747,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
mrb_free
(
mrb
,
buf
);
return
NULL
;
}
result
=
read_binary_header
(
buf
,
NULL
,
&
crc
,
NULL
);
result
=
read_binary_header
(
buf
,
NULL
,
&
crc
,
&
flags
);
mrb_free
(
mrb
,
buf
);
if
(
result
!=
MRB_DUMP_OK
)
{
return
NULL
;
...
...
@@ -807,7 +805,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
mrb_free
(
mrb
,
bin
);
return
NULL
;
}
result
=
read_section_debug
(
mrb
,
bin
,
irep
,
FLAG_SRC_MALLOC
);
result
=
read_section_debug
(
mrb
,
bin
,
irep
,
flags
);
mrb_free
(
mrb
,
bin
);
}
if
(
result
<
MRB_DUMP_OK
)
return
NULL
;
...
...
@@ -822,7 +820,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
mrb_free
(
mrb
,
bin
);
return
NULL
;
}
result
=
read_section_lv
(
mrb
,
bin
,
irep
,
FLAG_SRC_MALLOC
);
result
=
read_section_lv
(
mrb
,
bin
,
irep
,
flags
);
mrb_free
(
mrb
,
bin
);
}
if
(
result
<
MRB_DUMP_OK
)
return
NULL
;
...
...
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