From: cedric Date: Thu, 17 May 2012 09:56:28 +0000 (+0000) Subject: eina: don't assume that 'char' is a signed type in Eina_Value X-Git-Tag: submit/2.0alpha-wayland/20121127.222009~137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=daec48d3a5862c0f0f7334fa52736ea3826a63bf;p=profile%2Fivi%2Feina.git eina: don't assume that 'char' is a signed type in Eina_Value The eina_value code TYPE_CHAR conversion code assumes that 'char' is a signed type, which is not true on some platforms like ARM and PPC. We need to explicitely use signed chars to make sure the value is correct. Patch by Albin 'Lutin' Tonnerre git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@71195 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/ChangeLog b/ChangeLog index 7d61e5a..02b031f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -274,3 +274,7 @@ 2012-05-08 Cedric Bail * Add eina_file_map_lines to iterate on lines of a mapped file. + +2012-05-17 Albin Tonnerre + + * Fix portability issue of Eina_Value on ARM and PPC. diff --git a/NEWS b/NEWS index 5d82a9d..04dff63 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ Additions: Fixes: * Add missing files in the tarball. * Rounding issue with eina_f32p32_cos and eina_f32p32_sin when getting close to 1.0. + * Portability issue with Eina_Value when char are not signed by default (case on ARM + and PPC). Eina 1.2.0 diff --git a/src/include/eina_inline_value.x b/src/include/eina_inline_value.x index fa02c1a..4ca10e0 100644 --- a/src/include/eina_inline_value.x +++ b/src/include/eina_inline_value.x @@ -230,7 +230,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b) } else if (type == EINA_VALUE_TYPE_CHAR) { - char *ta = (char *) pa, *tb = (char *) pb; + signed char *ta = (signed char *) pa, *tb = (signed char *) pb; if (*ta < *tb) return -1; else if (*ta > *tb) @@ -376,7 +376,7 @@ eina_value_vset(Eina_Value *value, va_list args) } else if (type == EINA_VALUE_TYPE_CHAR) { - char *tmem = (char *) mem; + signed char *tmem = (signed char *) mem; *tmem = va_arg(args, int); /* promoted by va_arg */ return EINA_TRUE; } diff --git a/src/lib/eina_value.c b/src/lib/eina_value.c index e3c5a9c..5f76bbf 100644 --- a/src/lib/eina_value.c +++ b/src/lib/eina_value.c @@ -86,7 +86,7 @@ static int _eina_value_log_dom = -1; static const unsigned char eina_value_uchar_max = 255U; static const char eina_value_char_max = 127; -static const char eina_value_char_min = -127 - 1; +static const signed char eina_value_char_min = -127 - 1; static const unsigned short eina_value_ushort_max = 65535U; static const short eina_value_short_max = 32767; @@ -179,7 +179,7 @@ _eina_value_type_uchar_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max)) return EINA_FALSE; return eina_value_type_pset(convert, convert_mem, &other_mem); @@ -328,7 +328,7 @@ _eina_value_type_ushort_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max)) return EINA_FALSE; return eina_value_type_pset(convert, convert_mem, &other_mem); @@ -481,7 +481,7 @@ _eina_value_type_uint_convert_to(const Eina_Value_Type *type __UNUSED__, const E } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max)) return EINA_FALSE; return eina_value_type_pset(convert, convert_mem, &other_mem); @@ -638,7 +638,7 @@ _eina_value_type_ulong_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max)) return EINA_FALSE; return eina_value_type_pset(convert, convert_mem, &other_mem); @@ -800,7 +800,7 @@ _eina_value_type_uint64_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max)) return EINA_FALSE; return eina_value_type_pset(convert, convert_mem, &other_mem); @@ -965,7 +965,7 @@ _eina_value_type_char_convert_to(const Eina_Value_Type *type __UNUSED__, const E } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; return eina_value_type_pset(convert, convert_mem, &other_mem); } else if (convert == EINA_VALUE_TYPE_SHORT) @@ -1122,7 +1122,7 @@ _eina_value_type_short_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -1285,7 +1285,7 @@ _eina_value_type_int_convert_to(const Eina_Value_Type *type __UNUSED__, const Ei } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -1454,7 +1454,7 @@ _eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const E } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -1630,7 +1630,7 @@ _eina_value_type_int64_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -1812,7 +1812,7 @@ _eina_value_type_float_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -1996,7 +1996,7 @@ _eina_value_type_double_convert_to(const Eina_Value_Type *type __UNUSED__, const } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v; + signed char other_mem = v; if (EINA_UNLIKELY(v < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v > eina_value_char_max)) @@ -2165,7 +2165,7 @@ _eina_value_type_string_common_convert_to(const Eina_Value_Type *type __UNUSED__ } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem; + signed char other_mem; if ((sscanf(v, "%hhd", &other_mem) != 1) && (sscanf(v, "%hhx", &other_mem) != 1) && (sscanf(v, "%hho", &other_mem) != 1)) @@ -3503,7 +3503,7 @@ _eina_value_type_timeval_convert_to(const Eina_Value_Type *type __UNUSED__, cons } else if (convert == EINA_VALUE_TYPE_CHAR) { - char other_mem = v.tv_sec; + signed char other_mem = v.tv_sec; if (EINA_UNLIKELY(v.tv_sec < eina_value_char_min)) return EINA_FALSE; if (EINA_UNLIKELY(v.tv_sec > eina_value_char_max))