Refactoring and fixing jerry-libc

Refactor memory and string handling routines
* Potential code size improvements:
  * Most loops don't really need a new incrementing index variable
    running between 0..n-1 but can just loop `while (n--)`, and the
    bodies don't need array indexing but can just use the `*p++`
    idiom.
  * Compare routines are not required to return -1, 0, and +1, but
    any negative, zero, or positive result will do.
  * `strncmp` may follow the other routines and does not have to have
    defined behaviour if any of its args is NULL.
* Fix:
  * `strncmp` did not work correctly if the strings were equal but
    `n` was greater than their length (did not stop at the
    terminating zero character).

Refactor printf
* Merging code duplications, removing dead initialization.

Refactor rand and srand
* Making sure that the type of the state variables is OK
  (`uint32_t` instead of `unsigned int`).
* Getting type conversions OK.
* Fixing `srand` to write all state variables and thus indeed
  generate the same random sequence.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-02-07 00:29:33 +01:00
parent 684ed7268c
commit 3608f8df86
2 changed files with 60 additions and 101 deletions
+7 -26
View File
@@ -1,4 +1,5 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* 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.
@@ -210,23 +211,13 @@ libc_printf_write_d_i (FILE *stream, /**< stream pointer */
switch (length)
{
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: /* char is promoted to int */
case LIBC_PRINTF_ARG_LENGTH_TYPE_H: /* short int is promoted to int */
{
value = (uintmax_t) va_arg (*args_list_p, int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t) va_arg (*args_list_p, int); /* char is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t) va_arg (*args_list_p, int); /* short int is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t) va_arg (*args_list_p, long int);
@@ -324,23 +315,13 @@ libc_printf_write_u_o_x_X (FILE *stream, /**< stream pointer */
switch (length)
{
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: /* char is promoted to int */
case LIBC_PRINTF_ARG_LENGTH_TYPE_H: /* short int is promoted to int */
{
value = (uintmax_t) va_arg (*args_list_p, unsigned int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t) va_arg (*args_list_p, unsigned int); /* char is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t) va_arg (*args_list_p, unsigned int); /* short int is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t) va_arg (*args_list_p, unsigned long int);
@@ -398,7 +379,7 @@ libc_printf_write_u_o_x_X (FILE *stream, /**< stream pointer */
}
}
uint32_t radix = 10;
uint32_t radix;
const char *alphabet;
switch (specifier)