-
Notifications
You must be signed in to change notification settings - Fork 684
Added literal list loading feature to the snapshot tool. #2422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added literal list loading feature to the snapshot tool. #2422
Conversation
lit_utf8_size_t string_size = lit_zt_utf8_string_size (lit_get_magic_string_ex_utf8 (id)); | ||
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] == string_size); | ||
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] <= LIT_MAGIC_STRING_LENGTH_LIMIT); | ||
lit_utf8_size_t string_size = JERRY_CONTEXT (lit_magic_string_ex_sizes)[id]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the change is ok, I would keep the asserts in some form. They provide useful checks (maxlimit, cesu8 format).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be the limit? I don't know why was it constrained to 32. Do you know the reason?
lit_zt_utf8_string_size
cannot be used here, because strings can contain zeros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 32? that is new to me. Btw it would be good to remove the whole macro then.
No, you can trust the size provided by the user, but you should check that the string is valid cesu8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the check. Please check.
jerry-main/main-unix-snapshot.c
Outdated
{ | ||
char* sp_buffer_end_p = NULL; | ||
jerry_length_t mstr_size = (jerry_length_t) strtol (sp_buffer_p, &sp_buffer_end_p, 10); | ||
if (mstr_size > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check, but it can when the input file contains empty lines at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we detect that before calling strtol? What happens for invalid numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like this?
if ( '0' > *sp_buffer_p || *sp_buffer_p > '9')
{
break;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The format must be:
[0-9]+\s
and a valid cesu8 string which length is the number followed by a newline
If the newline is not present, the file must end.
If the file ends right before the number, that is valid as well.
jerry-main/main-unix-snapshot.c
Outdated
num_of_lit++; | ||
} | ||
sp_buffer_p = sp_buffer_end_p + mstr_size + 1; | ||
} while ((size_t)(sp_buffer_p - (char*) sp_buffer_start_p) < sp_buffer_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we do validation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g: JERRY_ASSERT (sp_buffer_p > (char*) sp_buffer_start_p)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the items are correct and correctly ordered. This is a tool, so even expensive validation is justified here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jerry_register_magic_strings
does the verification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only in debug mode. This is not a hard requirement, but I wouldn't mind doing a real check here, since it is not a difficult thing. Users may accidentally pass random files to this option.
{ | ||
if (save_literals_file_name_p != NULL) | ||
if (literals_file_name_p != NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot we both load and save literals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? The loaded and saved list can be different. Although loading probably used only with static snapshots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change this, but it is not a valid use case. It will never happen to use them in the same command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok keep it this way for now.
b9d238f
to
890a226
Compare
I've updated the PR. |
It is needed to load literals and register them as magic strings to be able to generate static snapshots. Also modified the list format saving feature to save all of the literals not only the identifiers. JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
890a226
to
5d9f5da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It is needed to load literals and register them as magic strings
to be able to generate static snapshots. Also modified the list
format saving feature to save all of the literals not only the
identifiers.
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]