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
85a2dfc8
Unverified
Commit
85a2dfc8
authored
May 22, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
May 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4403 from dearblue/read-irep-from-buf
Read irep from buffers
parents
38f8edbd
8f6f36f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
6 deletions
+49
-6
include/mruby/dump.h
include/mruby/dump.h
+1
-0
include/mruby/irep.h
include/mruby/irep.h
+12
-0
src/load.c
src/load.c
+36
-6
No files found.
include/mruby/dump.h
View file @
85a2dfc8
...
...
@@ -31,6 +31,7 @@ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
MRB_API
mrb_value
mrb_load_irep_file_cxt
(
mrb_state
*
,
FILE
*
,
mrbc_context
*
);
#endif
MRB_API
mrb_irep
*
mrb_read_irep
(
mrb_state
*
,
const
uint8_t
*
);
MRB_API
mrb_irep
*
mrb_read_irep_buf
(
mrb_state
*
,
const
void
*
,
size_t
);
/* dump/load error code
*
...
...
include/mruby/irep.h
View file @
85a2dfc8
...
...
@@ -52,9 +52,21 @@ MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API
mrb_value
mrb_load_irep
(
mrb_state
*
,
const
uint8_t
*
);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API
mrb_value
mrb_load_irep_buf
(
mrb_state
*
,
const
void
*
,
size_t
);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API
mrb_value
mrb_load_irep_cxt
(
mrb_state
*
,
const
uint8_t
*
,
mrbc_context
*
);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API
mrb_value
mrb_load_irep_buf_cxt
(
mrb_state
*
,
const
void
*
,
size_t
,
mrbc_context
*
);
void
mrb_irep_free
(
mrb_state
*
,
struct
mrb_irep
*
);
void
mrb_irep_incref
(
mrb_state
*
,
struct
mrb_irep
*
);
void
mrb_irep_decref
(
mrb_state
*
,
struct
mrb_irep
*
);
...
...
src/load.c
View file @
85a2dfc8
...
...
@@ -459,10 +459,14 @@ lv_exit:
}
static
int
read_binary_header
(
const
uint8_t
*
bin
,
size_t
*
bin_size
,
uint16_t
*
crc
,
uint8_t
*
flags
)
read_binary_header
(
const
uint8_t
*
bin
,
size_t
bufsize
,
size_t
*
bin_size
,
uint16_t
*
crc
,
uint8_t
*
flags
)
{
const
struct
rite_binary_header
*
header
=
(
const
struct
rite_binary_header
*
)
bin
;
if
(
bufsize
<
sizeof
(
struct
rite_binary_header
))
{
return
MRB_DUMP_READ_FAULT
;
}
if
(
memcmp
(
header
->
binary_ident
,
RITE_BINARY_IDENT
,
sizeof
(
header
->
binary_ident
))
==
0
)
{
if
(
bigendian_p
())
*
flags
|=
FLAG_BYTEORDER_NATIVE
;
...
...
@@ -479,16 +483,24 @@ read_binary_header(const uint8_t *bin, size_t *bin_size, uint16_t *crc, uint8_t
return
MRB_DUMP_INVALID_FILE_HEADER
;
}
if
(
memcmp
(
header
->
binary_version
,
RITE_BINARY_FORMAT_VER
,
sizeof
(
header
->
binary_version
))
!=
0
)
{
return
MRB_DUMP_INVALID_FILE_HEADER
;
}
if
(
crc
)
{
*
crc
=
bin_to_uint16
(
header
->
binary_crc
);
}
*
bin_size
=
(
size_t
)
bin_to_uint32
(
header
->
binary_size
);
if
(
bufsize
<
*
bin_size
)
{
return
MRB_DUMP_READ_FAULT
;
}
return
MRB_DUMP_OK
;
}
static
mrb_irep
*
read_irep
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
,
uint8_t
flags
)
read_irep
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
,
size_t
bufsize
,
uint8_t
flags
)
{
int
result
;
mrb_irep
*
irep
=
NULL
;
...
...
@@ -501,7 +513,7 @@ read_irep(mrb_state *mrb, const uint8_t *bin, uint8_t flags)
return
NULL
;
}
result
=
read_binary_header
(
bin
,
&
bin_size
,
&
crc
,
&
flags
);
result
=
read_binary_header
(
bin
,
bufsize
,
&
bin_size
,
&
crc
,
&
flags
);
if
(
result
!=
MRB_DUMP_OK
)
{
return
NULL
;
}
...
...
@@ -547,7 +559,13 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
uint8_t
flags
=
FLAG_SRC_STATIC
;
#endif
return
read_irep
(
mrb
,
bin
,
flags
);
return
read_irep
(
mrb
,
bin
,
(
size_t
)
-
1
,
flags
);
}
MRB_API
mrb_irep
*
mrb_read_irep_buf
(
mrb_state
*
mrb
,
const
void
*
buf
,
size_t
bufsize
)
{
return
read_irep
(
mrb
,
(
const
uint8_t
*
)
buf
,
bufsize
,
FLAG_SRC_MALLOC
);
}
void
mrb_exc_set
(
mrb_state
*
mrb
,
mrb_value
exc
);
...
...
@@ -583,12 +601,24 @@ mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
return
load_irep
(
mrb
,
mrb_read_irep
(
mrb
,
bin
),
c
);
}
MRB_API
mrb_value
mrb_load_irep_buf_cxt
(
mrb_state
*
mrb
,
const
void
*
buf
,
size_t
bufsize
,
mrbc_context
*
c
)
{
return
load_irep
(
mrb
,
mrb_read_irep_buf
(
mrb
,
buf
,
bufsize
),
c
);
}
MRB_API
mrb_value
mrb_load_irep
(
mrb_state
*
mrb
,
const
uint8_t
*
bin
)
{
return
mrb_load_irep_cxt
(
mrb
,
bin
,
NULL
);
}
MRB_API
mrb_value
mrb_load_irep_buf
(
mrb_state
*
mrb
,
const
void
*
buf
,
size_t
bufsize
)
{
return
mrb_load_irep_buf_cxt
(
mrb
,
buf
,
bufsize
,
NULL
);
}
#ifndef MRB_DISABLE_STDIO
mrb_irep
*
...
...
@@ -609,7 +639,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
if
(
fread
(
buf
,
header_size
,
1
,
fp
)
==
0
)
{
goto
irep_exit
;
}
result
=
read_binary_header
(
buf
,
&
buf_size
,
NULL
,
&
flags
);
result
=
read_binary_header
(
buf
,
(
size_t
)
-
1
,
&
buf_size
,
NULL
,
&
flags
);
if
(
result
!=
MRB_DUMP_OK
||
buf_size
<=
header_size
)
{
goto
irep_exit
;
}
...
...
@@ -618,7 +648,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
if
(
fread
(
buf
+
header_size
,
buf_size
-
header_size
,
1
,
fp
)
==
0
)
{
goto
irep_exit
;
}
irep
=
read_irep
(
mrb
,
buf
,
FLAG_SRC_MALLOC
);
irep
=
read_irep
(
mrb
,
buf
,
(
size_t
)
-
1
,
FLAG_SRC_MALLOC
);
irep_exit:
mrb_free
(
mrb
,
buf
);
...
...
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