Skip to content

Use port APIs instead of printf in non-debug code #956

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

Closed

Conversation

franc0is
Copy link
Contributor

JerryScript-DCO-1.0-Signed-off-by: François Baldassari francois@pebble.com

0,
JERRY_BITSINBYTE);

printf ("\\u%02x%02x", byte_high, byte_low);
jerry_port_putchar (byte_high);
jerry_port_putchar (byte_low);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

working on fixing this (see comments in #945)

@franc0is franc0is force-pushed the jerry-port-not-printf branch 2 times, most recently from d5b3840 to 79ce295 Compare March 11, 2016 01:43

jerry_port_putchar ('\\');
jerry_port_putchar ('u');
jerry_port_putchar (out_buf[0]);
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 don't love this, but it's the simplest way to achieve what I am trying to achieve without adding more port APIs.

@franc0is franc0is force-pushed the jerry-port-not-printf branch from 79ce295 to f471c2b Compare March 11, 2016 01:45
@franc0is
Copy link
Contributor Author

I think that's all the review comments

@franc0is franc0is force-pushed the jerry-port-not-printf branch 3 times, most recently from 91f49c2 to b40b489 Compare March 11, 2016 03:46
jerry_port_putchar ('u');
// print high byte
char out_buf[3];
itoa(byte_high, out_buf, 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like neither itoa nor sprintf is implemented in jerry-libc. What's the recommended solution here, I would happily add an itoa implementation.

@franc0is franc0is force-pushed the jerry-port-not-printf branch from b40b489 to 515e889 Compare March 11, 2016 18:46
@franc0is
Copy link
Contributor Author

Added a simple implementation of itoa. I don't think the end result is super elegant, but I couldn't come up with anything better that didn't involve more port APIs and pulling in an implementation of sprintf.

* Convert an integer to a string using base and write the result to buffer.
*/
char *
itoa (int value, char *buffer, int base)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation is not quite complete. It doesn't add the - sign for negative numbers and only accepts bases <= 16; but it is good enough for this use case.

@franc0is franc0is force-pushed the jerry-port-not-printf branch 3 times, most recently from 2b8f5c8 to 2194f0e Compare March 11, 2016 23:37
JerryScript-DCO-1.0-Signed-off-by: François Baldassari francois@pebble.com
@LaszloLango
Copy link
Contributor

Let's close this PR, because it is inactive in a long time and #1205 made this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants