@@ -5115,49 +5115,33 @@ jerry_log_set_level (jerry_log_level_t level)
51155115 * Log a zero-terminated string message.
51165116 *
51175117 * @param str_p: message
5118+ * @param str_size: size of message
51185119 */
51195120static void
5120- jerry_log_string (const char * str_p )
5121+ jerry_log_string (const jerry_char_t * str_p , jerry_size_t str_size )
51215122{
5122- jerry_port_log (str_p );
5123+ jerry_port_log_buffer (str_p , str_size );
51235124
51245125#if JERRY_DEBUGGER
51255126 if (jerry_debugger_is_connected ())
51265127 {
5127- jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT ,
5128- JERRY_DEBUGGER_OUTPUT_LOG ,
5129- (const uint8_t * ) str_p ,
5130- strlen (str_p ));
5128+ jerry_debugger_send_string (JERRY_DEBUGGER_OUTPUT_RESULT , JERRY_DEBUGGER_OUTPUT_LOG , str_p , str_size );
51315129 }
51325130#endif /* JERRY_DEBUGGER */
51335131} /* jerry_log_string */
51345132
51355133/**
5136- * Log a fixed-size string message.
5134+ * Log a zero-terminated number string message.
51375135 *
5138- * @param str_p: message
5139- * @param size: size
5140- * @param buffer_p: buffer to use
5136+ * @param cursor_p: the number string cursor
5137+ * @param buffer_p: buffer used to construct the number string
51415138 */
51425139static void
5143- jerry_log_string_fixed (const char * str_p , size_t size , char * buffer_p )
5140+ jerry_log_cursor (const jerry_char_t * cursor_p , jerry_char_t * buffer_p )
51445141{
5145- const size_t batch_size = JERRY_LOG_BUFFER_SIZE - 1 ;
5146-
5147- while (size > batch_size )
5148- {
5149- memcpy (buffer_p , str_p , batch_size );
5150- buffer_p [batch_size ] = '\0' ;
5151- jerry_log_string (buffer_p );
5152-
5153- str_p += batch_size ;
5154- size -= batch_size ;
5155- }
5156-
5157- memcpy (buffer_p , str_p , size );
5158- buffer_p [size ] = '\0' ;
5159- jerry_log_string (buffer_p );
5160- } /* jerry_log_string_fixed */
5142+ jerry_char_t * tail_p = buffer_p + JERRY_LOG_BUFFER_SIZE - 1 ;
5143+ jerry_log_string (cursor_p , (jerry_size_t ) (tail_p - cursor_p ));
5144+ } /* jerry_log_cursor */
51615145
51625146/**
51635147 * Format an unsigned number.
@@ -5170,11 +5154,13 @@ jerry_log_string_fixed (const char *str_p, size_t size, char *buffer_p)
51705154 *
51715155 * @return formatted number as string
51725156 */
5173- static char *
5174- jerry_format_unsigned (unsigned int num , uint8_t width , char padding , uint8_t radix , char * buffer_p )
5157+ static jerry_char_t *
5158+ jerry_format_unsigned (unsigned int num , uint8_t width , jerry_char_t padding , uint8_t radix , jerry_char_t * buffer_p )
51755159{
5176- static const char digits [] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
5177- char * cursor_p = buffer_p + JERRY_LOG_BUFFER_SIZE ;
5160+ static const jerry_char_t digits [] = {
5161+ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f'
5162+ };
5163+ jerry_char_t * cursor_p = buffer_p + JERRY_LOG_BUFFER_SIZE ;
51785164 * (-- cursor_p ) = '\0' ;
51795165 uint8_t count = 0 ;
51805166
@@ -5204,8 +5190,8 @@ jerry_format_unsigned (unsigned int num, uint8_t width, char padding, uint8_t ra
52045190 *
52055191 * @return formatted number as string
52065192 */
5207- static char *
5208- jerry_format_int (int num , uint8_t width , char padding , char * buffer_p )
5193+ static jerry_char_t *
5194+ jerry_format_int (int num , uint8_t width , jerry_char_t padding , jerry_char_t * buffer_p )
52095195{
52105196 if (num >= 0 )
52115197 {
@@ -5216,15 +5202,15 @@ jerry_format_int (int num, uint8_t width, char padding, char *buffer_p)
52165202
52175203 if (padding == '0' && width > 0 )
52185204 {
5219- char * cursor_p = jerry_format_unsigned ((unsigned ) num , -- width , padding , 10 , buffer_p );
5205+ jerry_char_t * cursor_p = jerry_format_unsigned ((unsigned ) num , -- width , padding , 10 , buffer_p );
52205206 * (-- cursor_p ) = '-' ;
52215207 return cursor_p ;
52225208 }
52235209
5224- char * cursor_p = jerry_format_unsigned ((unsigned ) num , 0 , ' ' , 10 , buffer_p );
5210+ jerry_char_t * cursor_p = jerry_format_unsigned ((unsigned ) num , 0 , ' ' , 10 , buffer_p );
52255211 * (-- cursor_p ) = '-' ;
52265212
5227- char * indent_p = buffer_p + JERRY_LOG_BUFFER_SIZE - width - 1 ;
5213+ jerry_char_t * indent_p = buffer_p + JERRY_LOG_BUFFER_SIZE - width - 1 ;
52285214
52295215 while (cursor_p > indent_p )
52305216 {
@@ -5258,17 +5244,17 @@ jerry_log (jerry_log_level_t level, const char *format_p, ...)
52585244 }
52595245
52605246 va_list vl ;
5261- char buffer_p [JERRY_LOG_BUFFER_SIZE ];
5262- uint32_t buffer_index = 0 ;
5263- const char * cursor_p = format_p ;
5247+ jerry_char_t buffer_p [JERRY_LOG_BUFFER_SIZE ];
5248+ jerry_size_t buffer_index = 0 ;
5249+ const jerry_char_t * cursor_p = ( const jerry_char_t * ) format_p ;
52645250 va_start (vl , format_p );
52655251
52665252 while (* cursor_p != '\0' )
52675253 {
52685254 if (* cursor_p == '%' || buffer_index > JERRY_LOG_BUFFER_SIZE - 2 )
52695255 {
52705256 buffer_p [buffer_index ] = '\0' ;
5271- jerry_log_string (buffer_p );
5257+ jerry_log_string (buffer_p , buffer_index );
52725258 buffer_index = 0 ;
52735259 }
52745260
@@ -5280,8 +5266,8 @@ jerry_log (jerry_log_level_t level, const char *format_p, ...)
52805266
52815267 ++ cursor_p ;
52825268 uint8_t width = 0 ;
5283- size_t precision = 0 ;
5284- char padding = ' ' ;
5269+ jerry_size_t precision = 0 ;
5270+ jerry_char_t padding = ' ' ;
52855271
52865272 if (* cursor_p == '0' )
52875273 {
@@ -5301,7 +5287,7 @@ jerry_log (jerry_log_level_t level, const char *format_p, ...)
53015287 }
53025288 else if (* cursor_p == '.' && * (cursor_p + 1 ) == '*' )
53035289 {
5304- precision = (size_t ) va_arg (vl , int );
5290+ precision = (jerry_size_t ) va_arg (vl , int );
53055291 cursor_p += 2 ;
53065292 }
53075293
@@ -5316,36 +5302,36 @@ jerry_log (jerry_log_level_t level, const char *format_p, ...)
53165302 {
53175303 case 's' :
53185304 {
5319- char * str_p = va_arg (vl , char * );
5305+ jerry_char_t * str_p = va_arg (vl , jerry_char_t * );
53205306
53215307 if (precision == 0 )
53225308 {
5323- jerry_log_string (str_p );
5309+ jerry_log_string (str_p , ( jerry_size_t ) strlen (( const char * ) str_p ) );
53245310 break ;
53255311 }
53265312
5327- jerry_log_string_fixed (str_p , precision , buffer_p );
5313+ jerry_log_string (str_p , precision );
53285314 break ;
53295315 }
53305316 case 'c' :
53315317 {
53325318 /* Arguments of types narrower than int are promoted to int for variadic functions */
5333- buffer_p [buffer_index ++ ] = (char ) va_arg (vl , int );
5319+ buffer_p [buffer_index ++ ] = (jerry_char_t ) va_arg (vl , int );
53345320 break ;
53355321 }
53365322 case 'd' :
53375323 {
5338- jerry_log_string (jerry_format_int (va_arg (vl , int ), width , padding , buffer_p ));
5324+ jerry_log_cursor (jerry_format_int (va_arg (vl , int ), width , padding , buffer_p ), buffer_p );
53395325 break ;
53405326 }
53415327 case 'u' :
53425328 {
5343- jerry_log_string (jerry_format_unsigned (va_arg (vl , unsigned int ), width , padding , 10 , buffer_p ));
5329+ jerry_log_cursor (jerry_format_unsigned (va_arg (vl , unsigned int ), width , padding , 10 , buffer_p ), buffer_p );
53445330 break ;
53455331 }
53465332 case 'x' :
53475333 {
5348- jerry_log_string (jerry_format_unsigned (va_arg (vl , unsigned int ), width , padding , 16 , buffer_p ));
5334+ jerry_log_cursor (jerry_format_unsigned (va_arg (vl , unsigned int ), width , padding , 16 , buffer_p ), buffer_p );
53495335 break ;
53505336 }
53515337 default :
@@ -5359,7 +5345,7 @@ jerry_log (jerry_log_level_t level, const char *format_p, ...)
53595345 if (buffer_index > 0 )
53605346 {
53615347 buffer_p [buffer_index ] = '\0' ;
5362- jerry_log_string (buffer_p );
5348+ jerry_log_string (buffer_p , buffer_index );
53635349 }
53645350
53655351 va_end (vl );
0 commit comments