Skip to content

Commit 8c2e41b

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 8c2e41b

File tree

9 files changed

+155
-137
lines changed

9 files changed

+155
-137
lines changed

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

Lines changed: 6 additions & 6 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",
@@ -97,11 +97,11 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
9797

9898
if (code_unit == LIT_CHAR_NULL)
9999
{
100-
printf ("\\u0000");
100+
jerry_port_console ("\\u0000");
101101
}
102102
else if (code_unit <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
103103
{
104-
printf ("%c", (char) code_unit);
104+
jerry_port_console ("%c", (char) code_unit);
105105
}
106106
else
107107
{
@@ -115,21 +115,21 @@ ecma_builtin_global_object_print (ecma_value_t this_arg, /**< this argument */
115115
0,
116116
JERRY_BITSINBYTE);
117117

118-
printf ("\\u%02x%02x", byte_high, byte_low);
118+
jerry_port_console ("\\u%02x%02x", byte_high, byte_low);
119119
}
120120
}
121121

122122
if (arg_index < args_number - 1)
123123
{
124-
printf (" ");
124+
jerry_port_console (" ");
125125
}
126126

127127
JMEM_FINALIZE_LOCAL_ARRAY (utf8_str_p);
128128

129129
ECMA_FINALIZE (str_value);
130130
}
131131

132-
printf ("\n");
132+
jerry_port_console ("\n");
133133

134134
if (ecma_is_value_empty (ret_value))
135135
{

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: 25 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_console ("Error: ");
3738

3839
switch (code)
3940
{
4041
case ERR_OUT_OF_MEMORY:
4142
{
42-
printf ("ERR_OUT_OF_MEMORY\n");
43+
jerry_port_console ("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_console ("ERR_REF_COUNT_LIMIT\n");
5354
break;
5455
}
5556
case ERR_UNIMPLEMENTED_CASE:
5657
{
57-
printf ("ERR_UNIMPLEMENTED_CASE\n");
58+
jerry_port_console ("ERR_UNIMPLEMENTED_CASE\n");
5859
break;
5960
}
6061
case ERR_FAILED_INTERNAL_ASSERTION:
6162
{
62-
printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
63+
jerry_port_console ("ERR_FAILED_INTERNAL_ASSERTION\n");
6364
break;
6465
}
6566
}
@@ -83,8 +84,11 @@ 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_console ("ICE: Assertion '%s' failed at %s(%s):%lu.\n",
88+
assertion,
89+
file,
90+
function,
91+
(unsigned long) line);
8892
#else /* JERRY_NDEBUG */
8993
(void) assertion;
9094
(void) file;
@@ -106,7 +110,10 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
106110
const uint32_t line) /**< line */
107111
{
108112
#ifndef JERRY_NDEBUG
109-
printf ("ICE: Unreachable control path at %s(%s):%lu was executed", file, function, (unsigned long) line);
113+
jerry_port_console ("ICE: Unreachable control path at %s(%s):%lu was executed",
114+
file,
115+
function,
116+
(unsigned long) line);
110117
#else /* JERRY_NDEBUG */
111118
(void) file;
112119
(void) function;
@@ -115,9 +122,10 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
115122

116123
if (comment != NULL)
117124
{
118-
printf ("(%s)", comment);
125+
jerry_port_console ("(%s)", comment);
119126
}
120-
printf (".\n");
127+
128+
jerry_port_console (".\n");
121129

122130
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
123131
} /* jerry_unreachable */
@@ -133,7 +141,10 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
133141
const uint32_t line) /**< line */
134142
{
135143
#ifndef JERRY_NDEBUG
136-
printf ("SORRY: Unimplemented case at %s(%s):%lu was executed", file, function, (unsigned long) line);
144+
jerry_port_console ("SORRY: Unimplemented case at %s(%s):%lu was executed",
145+
file,
146+
function,
147+
(unsigned long) line);
137148
#else /* JERRY_NDEBUG */
138149
(void) file;
139150
(void) function;
@@ -142,9 +153,10 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
142153

143154
if (comment != NULL)
144155
{
145-
printf ("(%s)", comment);
156+
jerry_port_console ("(%s)", comment);
146157
}
147-
printf (".\n");
158+
159+
jerry_port_console (".\n");
148160

149161
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
150162
} /* 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

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,39 +170,39 @@ parser_flush_cbc (parser_context_t *context_p) /**< context */
170170
name_p = cbc_ext_names[PARSER_GET_EXT_OPCODE (context_p->last_cbc_opcode)];
171171
}
172172

173-
printf (" [%3d] %s", (int) context_p->stack_depth, name_p);
173+
jerry_port_console (" [%3d] %s", (int) context_p->stack_depth, name_p);
174174

175175
if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2))
176176
{
177177
uint16_t literal_index = context_p->last_cbc.literal_index;
178178
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
179-
printf (" idx:%d->", literal_index);
179+
jerry_port_console (" idx:%d->", literal_index);
180180
util_print_literal (literal_p);
181181
}
182182

183183
if (flags & CBC_HAS_LITERAL_ARG2)
184184
{
185185
uint16_t literal_index = context_p->last_cbc.value;
186186
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
187-
printf (" idx:%d->", literal_index);
187+
jerry_port_console (" idx:%d->", literal_index);
188188
util_print_literal (literal_p);
189189

190190
if (!(flags & CBC_HAS_LITERAL_ARG))
191191
{
192192
literal_index = context_p->last_cbc.third_literal_index;
193193

194194
lexer_literal_t *literal_p = PARSER_GET_LITERAL (literal_index);
195-
printf (" idx:%d->", literal_index);
195+
jerry_port_console (" idx:%d->", literal_index);
196196
util_print_literal (literal_p);
197197
}
198198
}
199199

200200
if (flags & CBC_HAS_BYTE_ARG)
201201
{
202-
printf (" byte_arg:%d", (int) context_p->last_cbc.value);
202+
jerry_port_console (" byte_arg:%d", (int) context_p->last_cbc.value);
203203
}
204204

205-
printf ("\n");
205+
jerry_port_console ("\n");
206206
}
207207
#endif /* PARSER_DUMP_BYTE_CODE */
208208

@@ -327,7 +327,7 @@ parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */
327327
real_value = -real_value;
328328
}
329329

330-
printf (" [%3d] %s number:%d\n", (int) context_p->stack_depth, cbc_names[opcode], real_value);
330+
jerry_port_console (" [%3d] %s number:%d\n", (int) context_p->stack_depth, cbc_names[opcode], real_value);
331331
}
332332
#endif /* PARSER_DUMP_BYTE_CODE */
333333

@@ -391,11 +391,11 @@ parser_emit_cbc_forward_branch (parser_context_t *context_p, /**< context */
391391
{
392392
if (extra_byte_code_increase == 0)
393393
{
394-
printf (" [%3d] %s\n", (int) context_p->stack_depth, cbc_names[opcode]);
394+
jerry_port_console (" [%3d] %s\n", (int) context_p->stack_depth, cbc_names[opcode]);
395395
}
396396
else
397397
{
398-
printf (" [%3d] %s\n", (int) context_p->stack_depth, cbc_ext_names[opcode]);
398+
jerry_port_console (" [%3d] %s\n", (int) context_p->stack_depth, cbc_ext_names[opcode]);
399399
}
400400
}
401401
#endif /* PARSER_DUMP_BYTE_CODE */
@@ -506,7 +506,7 @@ parser_emit_cbc_backward_branch (parser_context_t *context_p, /**< context */
506506
#ifdef PARSER_DUMP_BYTE_CODE
507507
if (context_p->is_show_opcodes)
508508
{
509-
printf (" [%3d] %s\n", (int) context_p->stack_depth, name);
509+
jerry_port_console (" [%3d] %s\n", (int) context_p->stack_depth, name);
510510
}
511511
#endif /* PARSER_DUMP_BYTE_CODE */
512512

0 commit comments

Comments
 (0)