Skip to content

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

Merged
merged 1 commit into from
Jul 27, 2016

Conversation

slaff
Copy link
Contributor

@slaff slaff commented Jul 17, 2016

Fixes issue #1211.

@LaszloLango LaszloLango added the jerry-port Related to the port API or the default port implementation label Jul 18, 2016
@LaszloLango
Copy link
Contributor

@slaff, thanks for fixing the ESP8266 port. Please fix your sing-off in the commit message. Check travis logs for details:

Signed-off-by message is incorrect. The following line should be at the end of the 85b5195 commit's message: 'JerryScript-DCO-1.0-Signed-off-by: Slavey Karadzhov [email protected]'.

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__, \
Copy link
Contributor

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

@slaff
Copy link
Contributor Author

slaff commented Jul 18, 2016

@LaszloLango is there an automated script that fixes the coding style issues or at least reports them?

@LaszloLango
Copy link
Contributor

@slaff, make check-vera checks the coding style, but unfortunately it does not check the target folder, because it is allowed to use different style there. The only requirement is to use consistence style. For example if you put a space before parenthesis in function calls, then put it everywhere.

To follow Jerry style you can call vera++ manually to your source folder:
./tools/check-vera.sh targets/esp8266/source/

jerry_api_release_value (&res);

if (jerry_value_has_error_flag (res)) {
ret_code = -3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

@LaszloLango
Copy link
Contributor

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.

@slaff
Copy link
Contributor Author

slaff commented Jul 19, 2016

@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)))
Copy link
Contributor

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

@LaszloLango
Copy link
Contributor

LGTM after all of the tab characters are removed. Yes, please squash the commits and rebase to the current master.

@slaff
Copy link
Contributor Author

slaff commented Jul 19, 2016

@LaszloLango I've added the tab fixes, rebased on current master, and squashed the commits.

@LaszloLango
Copy link
Contributor

@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],
Copy link
Member

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.

Copy link
Contributor

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 :)

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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. :)

@slaff slaff force-pushed the master branch 3 times, most recently from fe4f8e3 to 2c83fd7 Compare July 19, 2016 14:52
jerry_string_to_char_buffer (args_p[cc],
(jerry_char_t *) buffer,
maxsize);
*(buffer + size) = 0;
Copy link
Member

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
Copy link
Contributor

@slaff, please update PR as @zherczeg suggested. I think after that change we can land your PR.

@slaff
Copy link
Contributor Author

slaff commented Jul 21, 2016

@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.

@LaszloLango
Copy link
Contributor

@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);
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@LaszloLango
Copy link
Contributor

LGTM

@zherczeg
Copy link
Member

LGTM. Please squash the commits and rebase it to the current master.

@slaff
Copy link
Contributor Author

slaff commented Jul 27, 2016

LGTM. Please squash the commits and rebase it to the current master.

@zherczeg Done

@zherczeg zherczeg merged commit 23db8b5 into jerryscript-project:master Jul 27, 2016
@zherczeg
Copy link
Member

Landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jerry-port Related to the port API or the default port implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants