Skip to content

Remove printf calls from jerry core #1205

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions jerry-core/ecma/builtin-objects/ecma-builtin-global.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/**
* The implementation-defined Global object's 'print' routine
*
* The routine converts all of its arguments to strings and outputs them using 'printf'.
* The routine converts all of its arguments to strings and outputs them using 'jerry_port_console'.
*
* Code points, with except of NUL character, that are representable with one utf8-byte
* are outputted as is, using "%c" format argument, and other code points are outputted as "\uhhll",
Expand All @@ -68,8 +68,6 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
JERRY_UNUSED (this_arg);
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);

/* TODO: Move the 'print' routine out of engine core. */

for (ecma_length_t arg_index = 0;
ecma_is_value_empty (ret_value) && arg_index < args_number;
arg_index++)
Expand Down Expand Up @@ -97,11 +95,11 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */

if (code_unit == LIT_CHAR_NULL)
{
printf ("\\u0000");
jerry_port_console ("\\u0000");
}
else if (code_unit <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
{
printf ("%c", (char) code_unit);
jerry_port_console ("%c", (char) code_unit);
}
else
{
Expand All @@ -115,21 +113,21 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
0,
JERRY_BITSINBYTE);

printf ("\\u%02x%02x", byte_high, byte_low);
jerry_port_console ("\\u%02x%02x", byte_high, byte_low);
}
}

if (arg_index < args_number - 1)
{
printf (" ");
jerry_port_console (" ");
}

JMEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);

ECMA_FINALIZE (str_value);
}

printf ("\n");
jerry_port_console ("\n");

if (ecma_is_value_empty (ret_value))
{
Expand Down
43 changes: 22 additions & 21 deletions jerry-core/jmem/jmem-heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,27 +609,28 @@ jmem_heap_stats_print (void)
{
jmem_heap_stats_t *heap_stats = &JERRY_CONTEXT (jmem_heap_stats);

printf ("Heap stats:\n"
" Heap size = %zu bytes\n"
" Allocated = %zu bytes\n"
" Waste = %zu bytes\n"
" Peak allocated = %zu bytes\n"
" Peak waste = %zu bytes\n"
" Skip-ahead ratio = %zu.%04zu\n"
" Average alloc iteration = %zu.%04zu\n"
" Average free iteration = %zu.%04zu\n"
"\n",
heap_stats->size,
heap_stats->allocated_bytes,
heap_stats->waste_bytes,
heap_stats->peak_allocated_bytes,
heap_stats->peak_waste_bytes,
heap_stats->skip_count / heap_stats->nonskip_count,
heap_stats->skip_count % heap_stats->nonskip_count * 10000 / heap_stats->nonskip_count,
heap_stats->alloc_iter_count / heap_stats->alloc_count,
heap_stats->alloc_iter_count % heap_stats->alloc_count * 10000 / heap_stats->alloc_count,
heap_stats->free_iter_count / heap_stats->free_count,
heap_stats->free_iter_count % heap_stats->free_count * 10000 / heap_stats->free_count);
jerry_port_log (JERRY_LOG_LEVEL_DEBUG,
"Heap stats:\n"
" Heap size = %zu bytes\n"
" Allocated = %zu bytes\n"
" Waste = %zu bytes\n"
" Peak allocated = %zu bytes\n"
" Peak waste = %zu bytes\n"
" Skip-ahead ratio = %zu.%04zu\n"
" Average alloc iteration = %zu.%04zu\n"
" Average free iteration = %zu.%04zu\n"
"\n",
heap_stats->size,
heap_stats->allocated_bytes,
heap_stats->waste_bytes,
heap_stats->peak_allocated_bytes,
heap_stats->peak_waste_bytes,
heap_stats->skip_count / heap_stats->nonskip_count,
heap_stats->skip_count % heap_stats->nonskip_count * 10000 / heap_stats->nonskip_count,
heap_stats->alloc_iter_count / heap_stats->alloc_count,
heap_stats->alloc_iter_count % heap_stats->alloc_count * 10000 / heap_stats->alloc_count,
heap_stats->free_iter_count / heap_stats->free_count,
heap_stats->free_iter_count % heap_stats->free_count * 10000 / heap_stats->free_count);
} /* jmem_heap_stats_print */

/**
Expand Down
25 changes: 13 additions & 12 deletions jerry-core/jmem/jmem-poolman.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,19 @@ jmem_pools_stats_print (void)
{
jmem_pools_stats_t *pools_stats = &JERRY_CONTEXT (jmem_pools_stats);

printf ("Pools stats:\n"
" Chunk size: %zu\n"
" Pool chunks: %zu\n"
" Peak pool chunks: %zu\n"
" Free chunks: %zu\n"
" Pool reuse ratio: %zu.%04zu\n",
JMEM_POOL_CHUNK_SIZE,
pools_stats->pools_count,
pools_stats->peak_pools_count,
pools_stats->free_chunks,
pools_stats->reused_count / pools_stats->new_alloc_count,
pools_stats->reused_count % pools_stats->new_alloc_count * 10000 / pools_stats->new_alloc_count);
jerry_port_log (JERRY_LOG_LEVEL_DEBUG,
"Pools stats:\n"
" Chunk size: %zu\n"
" Pool chunks: %zu\n"
" Peak pool chunks: %zu\n"
" Free chunks: %zu\n"
" Pool reuse ratio: %zu.%04zu\n",
JMEM_POOL_CHUNK_SIZE,
pools_stats->pools_count,
pools_stats->peak_pools_count,
pools_stats->free_chunks,
pools_stats->reused_count / pools_stats->new_alloc_count,
pools_stats->reused_count % pools_stats->new_alloc_count * 10000 / pools_stats->new_alloc_count);
} /* jmem_pools_stats_print */

/**
Expand Down
41 changes: 28 additions & 13 deletions jerry-core/jrt/jrt-fatals.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,13 +34,13 @@ void __noreturn
jerry_fatal (jerry_fatal_code_t code) /**< status code */
{
#ifndef JERRY_NDEBUG
printf ("Error: ");
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: ");

switch (code)
{
case ERR_OUT_OF_MEMORY:
{
printf ("ERR_OUT_OF_MEMORY\n");
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
Expand All @@ -49,17 +50,17 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
}
case ERR_REF_COUNT_LIMIT:
{
printf ("ERR_REF_COUNT_LIMIT\n");
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_REF_COUNT_LIMIT\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
printf ("ERR_UNIMPLEMENTED_CASE\n");
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
Expand All @@ -83,8 +84,12 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
const uint32_t line) /**< line */
{
#ifndef JERRY_NDEBUG
printf ("ICE: Assertion '%s' failed at %s(%s):%lu.\n",
assertion, file, function, (unsigned long) line);
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
"ICE: Assertion '%s' failed at %s(%s):%lu.\n",
assertion,
file,
function,
(unsigned long) line);
#else /* JERRY_NDEBUG */
(void) assertion;
(void) file;
Expand All @@ -106,7 +111,11 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
const uint32_t line) /**< line */
{
#ifndef JERRY_NDEBUG
printf ("ICE: Unreachable control path at %s(%s):%lu was executed", file, function, (unsigned long) line);
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
"ICE: Unreachable control path at %s(%s):%lu was executed",
file,
function,
(unsigned long) line);
#else /* JERRY_NDEBUG */
(void) file;
(void) function;
Expand All @@ -115,9 +124,10 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis

if (comment != NULL)
{
printf ("(%s)", comment);
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "(%s)", comment);
}
printf (".\n");

jerry_port_log (JERRY_LOG_LEVEL_ERROR, ".\n");

jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
Expand All @@ -133,7 +143,11 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
const uint32_t line) /**< line */
{
#ifndef JERRY_NDEBUG
printf ("SORRY: Unimplemented case at %s(%s):%lu was executed", file, function, (unsigned long) line);
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
"SORRY: Unimplemented case at %s(%s):%lu was executed",
file,
function,
(unsigned long) line);
#else /* JERRY_NDEBUG */
(void) file;
(void) function;
Expand All @@ -142,9 +156,10 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if

if (comment != NULL)
{
printf ("(%s)", comment);
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "(%s)", comment);
}
printf (".\n");

jerry_port_log (JERRY_LOG_LEVEL_ERROR, ".\n");

jerry_fatal (ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
20 changes: 10 additions & 10 deletions jerry-core/parser/js/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ util_print_chars (const uint8_t *char_p, /**< character pointer */
{
while (size > 0)
{
printf ("%c", *char_p++);
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "%c", *char_p++);
size--;
}
} /* util_print_chars */
Expand All @@ -73,7 +73,7 @@ util_print_number (ecma_number_t num_p) /**< number to print */
lit_utf8_byte_t str_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
lit_utf8_size_t str_size = ecma_number_to_utf8_string (num_p, str_buf, sizeof (str_buf));
str_buf[str_size] = 0;
printf ("%s", str_buf);
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "%s", str_buf);
} /* util_print_number */

/**
Expand All @@ -86,22 +86,22 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */
{
if (literal_p->status_flags & LEXER_FLAG_VAR)
{
printf ("var_ident(");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "var_ident(");
}
else
{
printf ("ident(");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "ident(");
}
util_print_chars (literal_p->u.char_p, literal_p->prop.length);
}
else if (literal_p->type == LEXER_FUNCTION_LITERAL)
{
printf ("function");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "function");
return;
}
else if (literal_p->type == LEXER_STRING_LITERAL)
{
printf ("string(");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "string(");
util_print_chars (literal_p->u.char_p, literal_p->prop.length);
}
else if (literal_p->type == LEXER_NUMBER_LITERAL)
Expand All @@ -110,21 +110,21 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */

JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);

printf ("number(");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "number(");
util_print_number (ecma_get_number_from_value (value_p->u.lit_number));
}
else if (literal_p->type == LEXER_REGEXP_LITERAL)
{
printf ("regexp");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "regexp");
return;
}
else
{
printf ("unknown");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "unknown");
return;
}

printf (")");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, ")");
} /* util_print_literal */

#endif /* PARSER_DUMP_BYTE_CODE */
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/parser/js/js-parser-statm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
if (context_p->is_show_opcodes
&& switch_to_strict_mode)
{
printf (" Note: switch to strict mode\n\n");
jerry_port_log (JERRY_LOG_LEVEL_DEBUG, " Note: switch to strict mode\n\n");
}
#endif /* PARSER_DUMP_BYTE_CODE */

Expand Down
Loading