Skip to content

Commit 378f56e

Browse files
committed
Remove printf calls from jerry core
Related issue: #964 JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent fa94c67 commit 378f56e

File tree

9 files changed

+158
-139
lines changed

9 files changed

+158
-139
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-global.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
/**
5252
* The implementation-defined Global object's 'print' routine
5353
*
54-
* The routine converts all of its arguments to strings and outputs them using 'printf'.
54+
* The routine converts all of its arguments to strings and outputs them using 'jerry_port_console'.
5555
*
5656
* Code points, with except of NUL character, that are representable with one utf8-byte
5757
* are outputted as is, using "%c" format argument, and other code points are outputted as "\uhhll",
@@ -68,8 +68,6 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
6868
JERRY_UNUSED (this_arg);
6969
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
7070

71-
/* TODO: Move the 'print' routine out of engine core. */
72-
7371
for (ecma_length_t arg_index = 0;
7472
ecma_is_value_empty (ret_value) && arg_index < args_number;
7573
arg_index++)
@@ -97,11 +95,11 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
9795

9896
if (code_unit == LIT_CHAR_NULL)
9997
{
100-
printf ("\\u0000");
98+
jerry_port_console ("\\u0000");
10199
}
102100
else if (code_unit <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
103101
{
104-
printf ("%c", (char) code_unit);
102+
jerry_port_console ("%c", (char) code_unit);
105103
}
106104
else
107105
{
@@ -115,21 +113,21 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
115113
0,
116114
JERRY_BITSINBYTE);
117115

118-
printf ("\\u%02x%02x", byte_high, byte_low);
116+
jerry_port_console ("\\u%02x%02x", byte_high, byte_low);
119117
}
120118
}
121119

122120
if (arg_index < args_number - 1)
123121
{
124-
printf (" ");
122+
jerry_port_console (" ");
125123
}
126124

127125
JMEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
128126

129127
ECMA_FINALIZE (str_value);
130128
}
131129

132-
printf ("\n");
130+
jerry_port_console ("\n");
133131

134132
if (ecma_is_value_empty (ret_value))
135133
{

jerry-core/jmem/jmem-heap.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -650,27 +650,30 @@ jmem_heap_stats_reset_peak (void)
650650
void
651651
jmem_heap_stats_print (void)
652652
{
653-
printf ("Heap stats:\n"
654-
" Heap size = %zu bytes\n"
655-
" Allocated = %zu bytes\n"
656-
" Waste = %zu bytes\n"
657-
" Peak allocated = %zu bytes\n"
658-
" Peak waste = %zu bytes\n"
659-
" Skip-ahead ratio = %zu.%04zu\n"
660-
" Average alloc iteration = %zu.%04zu\n"
661-
" Average free iteration = %zu.%04zu\n"
662-
"\n",
663-
jmem_heap_stats.size,
664-
jmem_heap_stats.allocated_bytes,
665-
jmem_heap_stats.waste_bytes,
666-
jmem_heap_stats.peak_allocated_bytes,
667-
jmem_heap_stats.peak_waste_bytes,
668-
jmem_heap_stats.skip_count / jmem_heap_stats.nonskip_count,
669-
jmem_heap_stats.skip_count % jmem_heap_stats.nonskip_count * 10000 / jmem_heap_stats.nonskip_count,
670-
jmem_heap_stats.alloc_iter_count / jmem_heap_stats.alloc_count,
671-
jmem_heap_stats.alloc_iter_count % jmem_heap_stats.alloc_count * 10000 / jmem_heap_stats.alloc_count,
672-
jmem_heap_stats.free_iter_count / jmem_heap_stats.free_count,
673-
jmem_heap_stats.free_iter_count % jmem_heap_stats.free_count * 10000 / jmem_heap_stats.free_count);
653+
jerry_port_console ("Heap stats:\n"
654+
" Heap size = %zu bytes\n"
655+
" Allocated = %zu bytes\n"
656+
" Waste = %zu bytes\n"
657+
" Peak allocated = %zu bytes\n"
658+
" Peak waste = %zu bytes\n"
659+
" Skip-ahead ratio = %zu.%04zu\n"
660+
" Average alloc iteration = %zu.%04zu\n"
661+
" Average free iteration = %zu.%04zu\n"
662+
"\n",
663+
jmem_heap_stats.size,
664+
jmem_heap_stats.allocated_bytes,
665+
jmem_heap_stats.waste_bytes,
666+
jmem_heap_stats.peak_allocated_bytes,
667+
jmem_heap_stats.peak_waste_bytes,
668+
jmem_heap_stats.skip_count / jmem_heap_stats.nonskip_count,
669+
jmem_heap_stats.skip_count % jmem_heap_stats.nonskip_count
670+
* 10000 / jmem_heap_stats.nonskip_count,
671+
jmem_heap_stats.alloc_iter_count / jmem_heap_stats.alloc_count,
672+
jmem_heap_stats.alloc_iter_count % jmem_heap_stats.alloc_count
673+
* 10000 / jmem_heap_stats.alloc_count,
674+
jmem_heap_stats.free_iter_count / jmem_heap_stats.free_count,
675+
jmem_heap_stats.free_iter_count % jmem_heap_stats.free_count
676+
* 10000 / jmem_heap_stats.free_count);
674677
} /* jmem_heap_stats_print */
675678

676679
/**

jerry-core/jmem/jmem-poolman.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,19 @@ jmem_pools_stats_reset_peak (void)
220220
void
221221
jmem_pools_stats_print (void)
222222
{
223-
printf ("Pools stats:\n"
224-
" Chunk size: %zu\n"
225-
" Pool chunks: %zu\n"
226-
" Peak pool chunks: %zu\n"
227-
" Free chunks: %zu\n"
228-
" Pool reuse ratio: %zu.%04zu\n",
229-
JMEM_POOL_CHUNK_SIZE,
230-
jmem_pools_stats.pools_count,
231-
jmem_pools_stats.peak_pools_count,
232-
jmem_pools_stats.free_chunks,
233-
jmem_pools_stats.reused_count / jmem_pools_stats.new_alloc_count,
234-
jmem_pools_stats.reused_count % jmem_pools_stats.new_alloc_count * 10000 / jmem_pools_stats.new_alloc_count);
223+
jerry_port_console ("Pools stats:\n"
224+
" Chunk size: %zu\n"
225+
" Pool chunks: %zu\n"
226+
" Peak pool chunks: %zu\n"
227+
" Free chunks: %zu\n"
228+
" Pool reuse ratio: %zu.%04zu\n",
229+
JMEM_POOL_CHUNK_SIZE,
230+
jmem_pools_stats.pools_count,
231+
jmem_pools_stats.peak_pools_count,
232+
jmem_pools_stats.free_chunks,
233+
jmem_pools_stats.reused_count / jmem_pools_stats.new_alloc_count,
234+
jmem_pools_stats.reused_count % jmem_pools_stats.new_alloc_count
235+
* 10000 / jmem_pools_stats.new_alloc_count);
235236
} /* jmem_pools_stats_print */
236237

237238
/**

jerry-core/jrt/jrt-fatals.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -33,13 +34,13 @@ void __noreturn
3334
jerry_fatal (jerry_fatal_code_t code) /**< status code */
3435
{
3536
#ifndef JERRY_NDEBUG
36-
printf ("Error: ");
37+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: ");
3738

3839
switch (code)
3940
{
4041
case ERR_OUT_OF_MEMORY:
4142
{
42-
printf ("ERR_OUT_OF_MEMORY\n");
43+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_OUT_OF_MEMORY\n");
4344
break;
4445
}
4546
case ERR_SYSCALL:
@@ -49,17 +50,17 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
4950
}
5051
case ERR_REF_COUNT_LIMIT:
5152
{
52-
printf ("ERR_REF_COUNT_LIMIT\n");
53+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_REF_COUNT_LIMIT\n");
5354
break;
5455
}
5556
case ERR_UNIMPLEMENTED_CASE:
5657
{
57-
printf ("ERR_UNIMPLEMENTED_CASE\n");
58+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_UNIMPLEMENTED_CASE\n");
5859
break;
5960
}
6061
case ERR_FAILED_INTERNAL_ASSERTION:
6162
{
62-
printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
63+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ERR_FAILED_INTERNAL_ASSERTION\n");
6364
break;
6465
}
6566
}
@@ -83,8 +84,12 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
8384
const uint32_t line) /**< line */
8485
{
8586
#ifndef JERRY_NDEBUG
86-
printf ("ICE: Assertion '%s' failed at %s(%s):%lu.\n",
87-
assertion, file, function, (unsigned long) line);
87+
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
88+
"ICE: Assertion '%s' failed at %s(%s):%lu.\n",
89+
assertion,
90+
file,
91+
function,
92+
(unsigned long) line);
8893
#else /* JERRY_NDEBUG */
8994
(void) assertion;
9095
(void) file;
@@ -106,7 +111,11 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
106111
const uint32_t line) /**< line */
107112
{
108113
#ifndef JERRY_NDEBUG
109-
printf ("ICE: Unreachable control path at %s(%s):%lu was executed", file, function, (unsigned long) line);
114+
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
115+
"ICE: Unreachable control path at %s(%s):%lu was executed",
116+
file,
117+
function,
118+
(unsigned long) line);
110119
#else /* JERRY_NDEBUG */
111120
(void) file;
112121
(void) function;
@@ -115,9 +124,10 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
115124

116125
if (comment != NULL)
117126
{
118-
printf ("(%s)", comment);
127+
jerry_port_console ("(%s)", comment);
119128
}
120-
printf (".\n");
129+
130+
jerry_port_console (".\n");
121131

122132
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
123133
} /* jerry_unreachable */
@@ -133,7 +143,11 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
133143
const uint32_t line) /**< line */
134144
{
135145
#ifndef JERRY_NDEBUG
136-
printf ("SORRY: Unimplemented case at %s(%s):%lu was executed", file, function, (unsigned long) line);
146+
jerry_port_log (JERRY_LOG_LEVEL_ERROR,
147+
"SORRY: Unimplemented case at %s(%s):%lu was executed",
148+
file,
149+
function,
150+
(unsigned long) line);
137151
#else /* JERRY_NDEBUG */
138152
(void) file;
139153
(void) function;
@@ -142,9 +156,10 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
142156

143157
if (comment != NULL)
144158
{
145-
printf ("(%s)", comment);
159+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "(%s)", comment);
146160
}
147-
printf (".\n");
161+
162+
jerry_port_log (JERRY_LOG_LEVEL_ERROR, ".\n");
148163

149164
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
150165
} /* jerry_unimplemented */

jerry-core/parser/js/common.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ util_print_chars (const uint8_t *char_p, /**< character pointer */
5959
{
6060
while (size > 0)
6161
{
62-
printf ("%c", *char_p++);
62+
jerry_port_console ("%c", *char_p++);
6363
size--;
6464
}
6565
} /* util_print_chars */
@@ -73,7 +73,7 @@ util_print_number (ecma_number_t num_p) /**< number to print */
7373
lit_utf8_byte_t str_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
7474
lit_utf8_size_t str_size = ecma_number_to_utf8_string (num_p, str_buf, sizeof (str_buf));
7575
str_buf[str_size] = 0;
76-
printf ("%s", str_buf);
76+
jerry_port_console ("%s", str_buf);
7777
} /* util_print_number */
7878

7979
/**
@@ -86,22 +86,22 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */
8686
{
8787
if (literal_p->status_flags & LEXER_FLAG_VAR)
8888
{
89-
printf ("var_ident(");
89+
jerry_port_console ("var_ident(");
9090
}
9191
else
9292
{
93-
printf ("ident(");
93+
jerry_port_console ("ident(");
9494
}
9595
util_print_chars (literal_p->u.char_p, literal_p->prop.length);
9696
}
9797
else if (literal_p->type == LEXER_FUNCTION_LITERAL)
9898
{
99-
printf ("function");
99+
jerry_port_console ("function");
100100
return;
101101
}
102102
else if (literal_p->type == LEXER_STRING_LITERAL)
103103
{
104-
printf ("string(");
104+
jerry_port_console ("string(");
105105
util_print_chars (literal_p->u.char_p, literal_p->prop.length);
106106
}
107107
else if (literal_p->type == LEXER_NUMBER_LITERAL)
@@ -110,21 +110,21 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */
110110

111111
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
112112

113-
printf ("number(");
113+
jerry_port_console ("number(");
114114
util_print_number (ecma_get_number_from_value (value_p->u.lit_number));
115115
}
116116
else if (literal_p->type == LEXER_REGEXP_LITERAL)
117117
{
118-
printf ("regexp");
118+
jerry_port_console ("regexp");
119119
return;
120120
}
121121
else
122122
{
123-
printf ("unknown");
123+
jerry_port_console ("unknown");
124124
return;
125125
}
126126

127-
printf (")");
127+
jerry_port_console (")");
128128
} /* util_print_literal */
129129

130130
#endif /* PARSER_DUMP_BYTE_CODE */

jerry-core/parser/js/js-parser-statm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
16091609
if (context_p->is_show_opcodes
16101610
&& switch_to_strict_mode)
16111611
{
1612-
printf (" Note: switch to strict mode\n\n");
1612+
jerry_port_console (" Note: switch to strict mode\n\n");
16131613
}
16141614
#endif /* PARSER_DUMP_BYTE_CODE */
16151615

0 commit comments

Comments
 (0)