-
Notifications
You must be signed in to change notification settings - Fork 683
Initial refactoring of the code to match the latest API. #1212
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
Conversation
@slaff, thanks for fixing the ESP8266 port. Please fix your sing-off in the commit message. Check travis logs for details:
The commit message should mention ESP8266 and the related issue number too. |
const jerry_api_length_t args_cnt) | ||
static jerry_value_t \ | ||
NAME ## _handler (const jerry_value_t function_obj_p __UNSED__, \ | ||
const jerry_value_t this_p __UNSED__, \ |
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.
Please remove the _p
suffix. They are not pointers anymore. ex.: func_obj_val
and this_val
@LaszloLango is there an automated script that fixes the coding style issues or at least reports them? |
@slaff, To follow Jerry style you can call vera++ manually to your source folder: |
jerry_api_release_value (&res); | ||
|
||
if (jerry_value_has_error_flag (res)) { | ||
ret_code = -3; |
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.
wrong indentation
I gave a few more comments. Only minor style issues. I think it close to be ready to merge. Nice work. Thanks again for fixing this port. |
@LaszloLango I've made the recommended coding style changes. Should I squash the commits or you will squash them during merge? |
&& jerry_api_is_function (reg_func_p) | ||
&& jerry_api_is_constructor (reg_func_p))) | ||
if (!(jerry_value_is_function (reg_func_val) | ||
&& jerry_value_is_constructor (reg_func_val))) |
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.
tab character :( It breaks the indentation and make the code ugly
LGTM after all of the tab characters are removed. Yes, please squash the commits and rebase to the current master. |
@LaszloLango I've added the tab fixes, rebased on current master, and squashed the commits. |
@slaff, thanks. LGTM |
jerry_size_t size, maxsize; | ||
size = jerry_get_string_size (args_p[0]); | ||
maxsize = MIN(size, 126); | ||
jerry_string_to_char_buffer (args_p[cc], |
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 hope you are aware that if the buffer is too small, no bytes are copied.
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.
the line above should do the trick :)
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 the trick? I mean if string length > 126, than MIN() returns with 126, and no bytes will be copied since buffer is too small.
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 guess the initial code was to allow the native "print" function to print string(s) with max length of 128 characters. What do you suggest to be changed 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.
You can allocate a large enough buffer with malloc, or you can just print that string is too long.
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.
@zherczeg, the current code will load maximum 126 bytes into a 128 bytes buffer. How could it be too small?
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.
BTW, I agree that it would look nicer, if we always allocate the buffer with the appropriate size. I'm just trying to say here the current code is valid and should work. :)
fe4f8e3
to
2c83fd7
Compare
jerry_string_to_char_buffer (args_p[cc], | ||
(jerry_char_t *) buffer, | ||
maxsize); | ||
*(buffer + 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.
No the code is unfortunately not correct. This expression can be a buffer overrun, and a byte on the stack will be replaced with 0. But even if we change size to maxsize, a random character sequence will be printed for strings > 126 bytes.
@LaszloLango @zherczeg When you have time take a look at the updated native print function. In the worst cases I can remove the native "print" function because the built-in JavaScript function works just fine. |
@slaff, please fix your Sign-off in the commit message |
maxsize = MIN(size, 126); | ||
char *buffer; | ||
jerry_size_t size = jerry_get_string_size (args_p[0]); | ||
buffer = (char *) malloc(size+1); |
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.
Minor style issue: missing spaces
malloc (size + 1);
if (jerry_value_has_error_flag (res)) { | ||
ret_code = -3; | ||
} | ||
|
||
free (val_args); |
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.
Is this free call still needed?
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.
Thanks for noticing this. It is removed now.
LGTM |
LGTM. Please squash the commits and rebase it to the current master. |
Fixes issue jerryscript-project#1211. JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov [email protected]
@zherczeg Done |
Landed. |
Fixes issue #1211.