forked from enlightenment/efl
eina: massiv fix for Eina_Value.
Should be more portable and work with C++. NOTE: I still see an aliasing break in eina_value_pset, but wasn't able to figure how to solve it. SVN revision: 67065
This commit is contained in:
parent
dec27dd7de
commit
ebbf531b63
|
@ -20,6 +20,8 @@
|
||||||
#define EINA_INLINE_VALUE_X_
|
#define EINA_INLINE_VALUE_X_
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <alloca.h>
|
||||||
|
|
||||||
#include "eina_stringshare.h"
|
#include "eina_stringshare.h"
|
||||||
|
|
||||||
/* NOTE: most of value is implemented here for performance reasons */
|
/* NOTE: most of value is implemented here for performance reasons */
|
||||||
|
@ -127,7 +129,7 @@ eina_value_flush(Eina_Value *value)
|
||||||
{
|
{
|
||||||
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
||||||
{
|
{
|
||||||
if (value->value.ptr) eina_stringshare_del(value->value.ptr);
|
if (value->value.ptr) eina_stringshare_del((const char*) value->value.ptr);
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_STRING)
|
else if (type == EINA_VALUE_TYPE_STRING)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +163,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
#ifndef EINA_VALUE_NO_OPTIMIZE
|
#ifndef EINA_VALUE_NO_OPTIMIZE
|
||||||
if (type == EINA_VALUE_TYPE_UCHAR)
|
if (type == EINA_VALUE_TYPE_UCHAR)
|
||||||
{
|
{
|
||||||
unsigned char *ta = pa, *tb = pb;
|
unsigned char *ta = (unsigned char *) pa, *tb = (unsigned char *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -170,7 +172,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_USHORT)
|
else if (type == EINA_VALUE_TYPE_USHORT)
|
||||||
{
|
{
|
||||||
unsigned short *ta = pa, *tb = pb;
|
unsigned short *ta = (unsigned short *) pa, *tb = (unsigned short *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -179,7 +181,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_UINT)
|
else if (type == EINA_VALUE_TYPE_UINT)
|
||||||
{
|
{
|
||||||
unsigned int *ta = pa, *tb = pb;
|
unsigned int *ta = (unsigned int *) pa, *tb = (unsigned int *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -188,7 +190,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_ULONG)
|
else if (type == EINA_VALUE_TYPE_ULONG)
|
||||||
{
|
{
|
||||||
unsigned long *ta = pa, *tb = pb;
|
unsigned long *ta = (unsigned long *) pa, *tb = (unsigned long *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -197,7 +199,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_UINT64)
|
else if (type == EINA_VALUE_TYPE_UINT64)
|
||||||
{
|
{
|
||||||
uint64_t *ta = pa, *tb = pb;
|
uint64_t *ta = (uint64_t *) pa, *tb = (uint64_t *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -206,7 +208,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_CHAR)
|
else if (type == EINA_VALUE_TYPE_CHAR)
|
||||||
{
|
{
|
||||||
char *ta = pa, *tb = pb;
|
char *ta = (char *) pa, *tb = (char *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -215,7 +217,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_SHORT)
|
else if (type == EINA_VALUE_TYPE_SHORT)
|
||||||
{
|
{
|
||||||
short *ta = pa, *tb = pb;
|
short *ta = (short *) pa, *tb = (short *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -224,7 +226,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_INT)
|
else if (type == EINA_VALUE_TYPE_INT)
|
||||||
{
|
{
|
||||||
int *ta = pa, *tb = pb;
|
int *ta = (int *) pa, *tb = (int *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -233,7 +235,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_LONG)
|
else if (type == EINA_VALUE_TYPE_LONG)
|
||||||
{
|
{
|
||||||
long *ta = pa, *tb = pb;
|
long *ta = (long *) pa, *tb = (long *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -242,7 +244,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_INT64)
|
else if (type == EINA_VALUE_TYPE_INT64)
|
||||||
{
|
{
|
||||||
int64_t *ta = pa, *tb = pb;
|
int64_t *ta = (int64_t *) pa, *tb = (int64_t *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -251,7 +253,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_FLOAT)
|
else if (type == EINA_VALUE_TYPE_FLOAT)
|
||||||
{
|
{
|
||||||
float *ta = pa, *tb = pb;
|
float *ta = (float *) pa, *tb = (float *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -260,7 +262,7 @@ eina_value_compare(const Eina_Value *a, const Eina_Value *b)
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_DOUBLE)
|
else if (type == EINA_VALUE_TYPE_DOUBLE)
|
||||||
{
|
{
|
||||||
double *ta = pa, *tb = pb;
|
double *ta = (double *) pa, *tb = (double *) pb;
|
||||||
if (*ta < *tb)
|
if (*ta < *tb)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*ta > *tb)
|
else if (*ta > *tb)
|
||||||
|
@ -322,84 +324,84 @@ eina_value_vset(Eina_Value *value, va_list args)
|
||||||
#ifndef EINA_VALUE_NO_OPTIMIZE
|
#ifndef EINA_VALUE_NO_OPTIMIZE
|
||||||
if (type == EINA_VALUE_TYPE_UCHAR)
|
if (type == EINA_VALUE_TYPE_UCHAR)
|
||||||
{
|
{
|
||||||
unsigned char *tmem = mem;
|
unsigned char *tmem = (unsigned char *) mem;
|
||||||
*tmem = va_arg(args, unsigned int); /* promoted by va_arg */
|
*tmem = va_arg(args, unsigned int); /* promoted by va_arg */
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_USHORT)
|
else if (type == EINA_VALUE_TYPE_USHORT)
|
||||||
{
|
{
|
||||||
unsigned short *tmem = mem;
|
unsigned short *tmem = (unsigned short *) mem;
|
||||||
*tmem = va_arg(args, unsigned int); /* promoted by va_arg */
|
*tmem = va_arg(args, unsigned int); /* promoted by va_arg */
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_UINT)
|
else if (type == EINA_VALUE_TYPE_UINT)
|
||||||
{
|
{
|
||||||
unsigned int *tmem = mem;
|
unsigned int *tmem = (unsigned int *) mem;
|
||||||
*tmem = va_arg(args, unsigned int);
|
*tmem = va_arg(args, unsigned int);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_ULONG)
|
else if (type == EINA_VALUE_TYPE_ULONG)
|
||||||
{
|
{
|
||||||
unsigned long *tmem = mem;
|
unsigned long *tmem = (unsigned long *) mem;
|
||||||
*tmem = va_arg(args, unsigned long);
|
*tmem = va_arg(args, unsigned long);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_UINT64)
|
else if (type == EINA_VALUE_TYPE_UINT64)
|
||||||
{
|
{
|
||||||
uint64_t *tmem = mem;
|
uint64_t *tmem = (uint64_t *) mem;
|
||||||
*tmem = va_arg(args, uint64_t);
|
*tmem = va_arg(args, uint64_t);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_CHAR)
|
else if (type == EINA_VALUE_TYPE_CHAR)
|
||||||
{
|
{
|
||||||
char *tmem = mem;
|
char *tmem = (char *) mem;
|
||||||
*tmem = va_arg(args, int); /* promoted by va_arg */
|
*tmem = va_arg(args, int); /* promoted by va_arg */
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_SHORT)
|
else if (type == EINA_VALUE_TYPE_SHORT)
|
||||||
{
|
{
|
||||||
short *tmem = mem;
|
short *tmem = (short *) mem;
|
||||||
*tmem = va_arg(args, int); /* promoted by va_arg */
|
*tmem = va_arg(args, int); /* promoted by va_arg */
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_INT)
|
else if (type == EINA_VALUE_TYPE_INT)
|
||||||
{
|
{
|
||||||
int *tmem = mem;
|
int *tmem = (int *) mem;
|
||||||
*tmem = va_arg(args, int);
|
*tmem = va_arg(args, int);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_LONG)
|
else if (type == EINA_VALUE_TYPE_LONG)
|
||||||
{
|
{
|
||||||
long *tmem = mem;
|
long *tmem = (long *) mem;
|
||||||
*tmem = va_arg(args, long);
|
*tmem = va_arg(args, long);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_INT64)
|
else if (type == EINA_VALUE_TYPE_INT64)
|
||||||
{
|
{
|
||||||
int64_t *tmem = mem;
|
int64_t *tmem = (int64_t *) mem;
|
||||||
*tmem = va_arg(args, int64_t);
|
*tmem = va_arg(args, int64_t);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_FLOAT)
|
else if (type == EINA_VALUE_TYPE_FLOAT)
|
||||||
{
|
{
|
||||||
float *tmem = mem;
|
float *tmem = (float *) mem;
|
||||||
*tmem = va_arg(args, double); /* promoted by va_arg */
|
*tmem = va_arg(args, double); /* promoted by va_arg */
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_DOUBLE)
|
else if (type == EINA_VALUE_TYPE_DOUBLE)
|
||||||
{
|
{
|
||||||
double *tmem = mem;
|
double *tmem = (double *) mem;
|
||||||
*tmem = va_arg(args, double);
|
*tmem = va_arg(args, double);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
else if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
||||||
{
|
{
|
||||||
const char *str = va_arg(args, const char *);
|
const char *str = (const char *) va_arg(args, const char *);
|
||||||
return eina_stringshare_replace((const char **)&value->value.ptr, str);
|
return eina_stringshare_replace((const char **)&value->value.ptr, str);
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_STRING)
|
else if (type == EINA_VALUE_TYPE_STRING)
|
||||||
{
|
{
|
||||||
const char *str = va_arg(args, const char *);
|
const char *str = (const char *) va_arg(args, const char *);
|
||||||
free(value->value.ptr);
|
free(value->value.ptr);
|
||||||
if (!str)
|
if (!str)
|
||||||
value->value.ptr = NULL;
|
value->value.ptr = NULL;
|
||||||
|
@ -460,19 +462,23 @@ eina_value_pset(Eina_Value *value, const void *ptr)
|
||||||
{
|
{
|
||||||
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
if (type == EINA_VALUE_TYPE_STRINGSHARE)
|
||||||
{
|
{
|
||||||
const char * const *str = ptr;
|
const char * const *pstr = (const char * const *) ptr;
|
||||||
|
const char *str = *pstr;
|
||||||
|
|
||||||
return eina_stringshare_replace((const char **)&value->value.ptr,
|
return eina_stringshare_replace((const char **)&value->value.ptr,
|
||||||
*str);
|
str);
|
||||||
}
|
}
|
||||||
else if (type == EINA_VALUE_TYPE_STRING)
|
else if (type == EINA_VALUE_TYPE_STRING)
|
||||||
{
|
{
|
||||||
const char * const *str = ptr;
|
const char * const * pstr = (const char * const *) ptr;
|
||||||
|
const char *str = *pstr;
|
||||||
|
|
||||||
free(value->value.ptr);
|
free(value->value.ptr);
|
||||||
if (!*str)
|
if (!str)
|
||||||
value->value.ptr = NULL;
|
value->value.ptr = NULL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value->value.ptr = strdup(*str);
|
value->value.ptr = strdup(str);
|
||||||
if (!value->value.ptr)
|
if (!value->value.ptr)
|
||||||
{
|
{
|
||||||
eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
|
eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
|
||||||
|
@ -526,7 +532,7 @@ eina_value_type_get(const Eina_Value *value)
|
||||||
static inline Eina_Bool
|
static inline Eina_Bool
|
||||||
eina_value_array_setup(Eina_Value *value, const Eina_Value_Type *subtype, unsigned int step)
|
eina_value_array_setup(Eina_Value *value, const Eina_Value_Type *subtype, unsigned int step)
|
||||||
{
|
{
|
||||||
Eina_Value_Array desc = {subtype, step, NULL};
|
Eina_Value_Array desc = { subtype, step, NULL };
|
||||||
if (!eina_value_setup(value, EINA_VALUE_TYPE_ARRAY))
|
if (!eina_value_setup(value, EINA_VALUE_TYPE_ARRAY))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
if (!eina_value_pset(value, &desc))
|
if (!eina_value_pset(value, &desc))
|
||||||
|
|
|
@ -681,7 +681,7 @@ struct _Eina_Value_Array
|
||||||
const Eina_Value_Type *subtype; /**< how to allocate and access items */
|
const Eina_Value_Type *subtype; /**< how to allocate and access items */
|
||||||
unsigned int step; /**< how to grow the members array */
|
unsigned int step; /**< how to grow the members array */
|
||||||
Eina_Inarray *array; /**< the array that holds data, members are of subtype->value_size bytes. */
|
Eina_Inarray *array; /**< the array that holds data, members are of subtype->value_size bytes. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create generic value storage of type array.
|
* @brief Create generic value storage of type array.
|
||||||
|
|
|
@ -28,10 +28,9 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* _GNU_SOURCE: asprintf() */
|
#include <stdio.h> /* asprintf() */
|
||||||
#ifndef _GNU_SOURCE
|
#include <inttypes.h> /* PRId64 and PRIu64 */
|
||||||
#define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
#include "eina_config.h"
|
#include "eina_config.h"
|
||||||
#include "eina_private.h"
|
#include "eina_private.h"
|
||||||
#include "eina_error.h"
|
#include "eina_error.h"
|
||||||
|
@ -42,9 +41,6 @@
|
||||||
#include "eina_safety_checks.h"
|
#include "eina_safety_checks.h"
|
||||||
#include "eina_value.h"
|
#include "eina_value.h"
|
||||||
|
|
||||||
#include <stdio.h> /* asprintf() */
|
|
||||||
#include <inttypes.h> /* PRId64 and PRIu64 */
|
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Local *
|
* Local *
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
@ -981,7 +977,7 @@ _eina_value_type_char_compare(const Eina_Value_Type *type __UNUSED__, const void
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_eina_value_type_char_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
|
_eina_value_type_char_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
|
||||||
{
|
{
|
||||||
const char v = *(const char *)type_mem;
|
const signed char v = *(const signed char *)type_mem;
|
||||||
|
|
||||||
eina_error_set(0);
|
eina_error_set(0);
|
||||||
|
|
||||||
|
@ -1518,7 +1514,7 @@ _eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const E
|
||||||
unsigned char other_mem = v;
|
unsigned char other_mem = v;
|
||||||
if (EINA_UNLIKELY(v < 0))
|
if (EINA_UNLIKELY(v < 0))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
if (EINA_UNLIKELY(v > eina_value_uchar_max))
|
if (EINA_UNLIKELY((unsigned long) v > eina_value_uchar_max))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
||||||
}
|
}
|
||||||
|
@ -1527,7 +1523,7 @@ _eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const E
|
||||||
unsigned short other_mem = v;
|
unsigned short other_mem = v;
|
||||||
if (EINA_UNLIKELY(v < 0))
|
if (EINA_UNLIKELY(v < 0))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
if (EINA_UNLIKELY(v > eina_value_ushort_max))
|
if (EINA_UNLIKELY((unsigned long) v > eina_value_ushort_max))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
||||||
}
|
}
|
||||||
|
@ -1536,7 +1532,7 @@ _eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const E
|
||||||
unsigned int other_mem = v;
|
unsigned int other_mem = v;
|
||||||
if (EINA_UNLIKELY(v < 0))
|
if (EINA_UNLIKELY(v < 0))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
if (EINA_UNLIKELY(v > eina_value_uint_max))
|
if (EINA_UNLIKELY((unsigned long) v > eina_value_uint_max))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
return eina_value_type_pset(convert, convert_mem, &other_mem);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue