Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 3a701fb

Browse files
Jimmy Huanggrgustaf
Jimmy Huang
authored andcommitted
[snapshot] Fixed incorrect snapshot size (#1889)
JerryScript updated the generate_snapshot API to return a jerry_value instead of the size, so if you directly use the size returned, it will be incorrect and cause the final ROM size to not fit the board. Also fixes a buid error with dynamic mode. Fixes #1887 #1888, #1890 Signed-off-by: Jimmy Huang <[email protected]>
1 parent 2b033e1 commit 3a701fb

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ int main(int argc, char *argv[])
275275
#else
276276
#ifndef ZJS_ASHELL
277277
script_len = strnlen(script_jscode, MAX_SCRIPT_SIZE);
278-
script = script_jscode;
278+
script = (char *)script_jscode;
279279
#endif
280280
#endif
281281
if (script_len == MAX_SCRIPT_SIZE) {

src/zjs_modules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void zjs_modules_check_load_file()
279279
size_t size;
280280
jerry_value_t parsed_code = 0;
281281
buf = read_file_alloc(load_file, &size);
282-
parsed_code = jerry_parse(NULL, 0, const jerry_char_t *)buf, size,
282+
parsed_code = jerry_parse(NULL, 0, (const jerry_char_t *)buf, size,
283283
JERRY_PARSE_NO_OPTS);
284284
zjs_free(buf);
285285

tools/snapshot.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,28 @@ int main(int argc, char *argv[])
3939
return 1;
4040
}
4141

42-
size_t size = jerry_generate_snapshot(NULL,
43-
0,
44-
(const jerry_char_t *)script,
45-
len,
46-
0,
47-
snapshot_buf,
48-
sizeof(snapshot_buf));
42+
jerry_value_t snapshot_result;
43+
snapshot_result = jerry_generate_snapshot(NULL,
44+
0,
45+
(const jerry_char_t *)script,
46+
len,
47+
0,
48+
snapshot_buf,
49+
sizeof(snapshot_buf));
50+
51+
if (jerry_value_is_error(snapshot_result)) {
52+
fprintf(stderr, "JerryScript: failed to parse JS and create snapshot\n");
53+
return 1;
54+
}
55+
56+
size_t size = (size_t)jerry_get_number_value(snapshot_result);
57+
jerry_release_value(snapshot_result);
4958

5059
if (script != NULL)
5160
free(script);
5261

5362
if (size == 0) {
54-
fprintf(stderr, "JerryScript: failed to parse JS and create snapshot\n");
63+
fprintf(stderr, "JerryScript: snapshot size is zero\n");
5564
return 1;
5665
}
5766

0 commit comments

Comments
 (0)