summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-01-31 21:05:20 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-01-31 21:05:20 +0000
commitceb07e60d192889e6160ba5a6cbc66ac1b9cc3de (patch)
tree400f8229f49f9208fdf7b30ecbceef801219e714
parent128f5aa6e9fd3be0d6b14300e7a85987f2c9781d (diff)
eina_value: fix struct type.
1. consider case where the struct was not set for flush and others; 2. flush previous struct on pset; 3. setup the new struct members memory on pset; 4. always use ops->alloc and ops->free if they are provided; SVN revision: 67662
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/lib/eina_value.c86
1 files changed, 67 insertions, 19 deletions
diff --git a/legacy/eina/src/lib/eina_value.c b/legacy/eina/src/lib/eina_value.c
index eea6772a76..0c276c8386 100644
--- a/legacy/eina/src/lib/eina_value.c
+++ b/legacy/eina/src/lib/eina_value.c
@@ -3957,6 +3957,13 @@ _eina_value_type_struct_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3957} 3957}
3958 3958
3959static Eina_Bool 3959static Eina_Bool
3960_eina_value_type_struct_setup_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st)
3961{
3962 unsigned char *base = st->memory;
3963 return eina_value_type_setup(member->type, base + member->offset);
3964}
3965
3966static Eina_Bool
3960_eina_value_type_struct_flush_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st) 3967_eina_value_type_struct_flush_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st)
3961{ 3968{
3962 unsigned char *base = st->memory; 3969 unsigned char *base = st->memory;
@@ -3971,6 +3978,9 @@ _eina_value_type_struct_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3971 Eina_Value_Struct *tmem = mem; 3978 Eina_Value_Struct *tmem = mem;
3972 Eina_Bool ret = EINA_TRUE; 3979 Eina_Bool ret = EINA_TRUE;
3973 3980
3981 if ((!tmem->desc) || (!tmem->memory))
3982 return EINA_TRUE;
3983
3974 itr = tmem->desc->members; 3984 itr = tmem->desc->members;
3975 if (tmem->desc->member_count > 0) 3985 if (tmem->desc->member_count > 0)
3976 { 3986 {
@@ -4014,6 +4024,9 @@ _eina_value_type_struct_copy(const Eina_Value_Type *type __UNUSED__, const void
4014 4024
4015 *d = *s; 4025 *d = *s;
4016 4026
4027 if ((!s->desc) || (!s->memory))
4028 return EINA_TRUE;
4029
4017 ops = _eina_value_type_struct_ops_get(src); 4030 ops = _eina_value_type_struct_ops_get(src);
4018 if ((ops) && (ops->copy)) 4031 if ((ops) && (ops->copy))
4019 { 4032 {
@@ -4023,7 +4036,10 @@ _eina_value_type_struct_copy(const Eina_Value_Type *type __UNUSED__, const void
4023 return EINA_TRUE; 4036 return EINA_TRUE;
4024 } 4037 }
4025 4038
4026 d->memory = malloc(s->desc->size); 4039 if ((ops) && (ops->alloc))
4040 d->memory = ops->alloc(ops, s->desc);
4041 else
4042 d->memory = malloc(s->desc->size);
4027 if (!d->memory) 4043 if (!d->memory)
4028 { 4044 {
4029 eina_error_set(EINA_ERROR_OUT_OF_MEMORY); 4045 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
@@ -4045,14 +4061,17 @@ _eina_value_type_struct_copy(const Eina_Value_Type *type __UNUSED__, const void
4045 goto error; 4061 goto error;
4046 } 4062 }
4047 4063
4048
4049 return EINA_TRUE; 4064 return EINA_TRUE;
4050 4065
4051 error: 4066 error:
4052 itr--; 4067 itr--;
4053 for (; itr >= s->desc->members; itr--) 4068 for (; itr >= s->desc->members; itr--)
4054 _eina_value_type_struct_flush_member(itr, d); 4069 _eina_value_type_struct_flush_member(itr, d);
4055 free(d->memory); 4070
4071 if ((ops) && (ops->free))
4072 ops->free(ops, s->desc, d->memory);
4073 else
4074 free(d->memory);
4056 return EINA_FALSE; 4075 return EINA_FALSE;
4057} 4076}
4058 4077
@@ -4074,7 +4093,9 @@ _eina_value_type_struct_compare(const Eina_Value_Type *type __UNUSED__, const vo
4074 const Eina_Value_Struct_Member *itr; 4093 const Eina_Value_Struct_Member *itr;
4075 int cmp = 0; 4094 int cmp = 0;
4076 4095
4077 if (ta->desc != tb->desc) 4096 if ((!ta->desc) && (!tb->desc))
4097 return 0;
4098 else if (ta->desc != tb->desc)
4078 { 4099 {
4079 eina_error_set(EINA_ERROR_VALUE_FAILED); 4100 eina_error_set(EINA_ERROR_VALUE_FAILED);
4080 return -1; 4101 return -1;
@@ -4238,11 +4259,12 @@ _eina_value_type_struct_desc_check(const Eina_Value_Struct_Desc *desc)
4238} 4259}
4239 4260
4240static Eina_Bool 4261static Eina_Bool
4241_eina_value_type_struct_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr) 4262_eina_value_type_struct_pset(const Eina_Value_Type *type, void *mem, const void *ptr)
4242{ 4263{
4243 const Eina_Value_Struct_Operations *ops = _eina_value_type_struct_ops_get(mem); 4264 const Eina_Value_Struct_Operations *ops;
4244 Eina_Value_Struct *tmem = mem; 4265 Eina_Value_Struct *tmem = mem;
4245 const Eina_Value_Struct *desc = ptr; 4266 const Eina_Value_Struct *desc = ptr;
4267 const Eina_Value_Struct_Member *itr;
4246 4268
4247 if (!_eina_value_type_struct_desc_check(desc->desc)) 4269 if (!_eina_value_type_struct_desc_check(desc->desc))
4248 { 4270 {
@@ -4250,30 +4272,56 @@ _eina_value_type_struct_pset(const Eina_Value_Type *type __UNUSED__, void *mem,
4250 return EINA_FALSE; 4272 return EINA_FALSE;
4251 } 4273 }
4252 4274
4253 if ((ops) && (ops->free)) 4275 _eina_value_type_struct_flush(type, mem);
4254 ops->free(ops, tmem->desc, tmem->memory);
4255 else
4256 free(tmem->memory);
4257 4276
4258 *tmem = *desc; 4277 *tmem = *desc;
4278 if (tmem->memory)
4279 {
4280 eina_error_set(0);
4281 return EINA_TRUE;
4282 }
4259 4283
4260 ops = _eina_value_type_struct_ops_get(desc); 4284 ops = _eina_value_type_struct_ops_get(desc);
4285 if ((ops) && (ops->alloc))
4286 tmem->memory = ops->alloc(ops, tmem->desc);
4287 else
4288 tmem->memory = malloc(tmem->desc->size);
4289
4261 if (!tmem->memory) 4290 if (!tmem->memory)
4262 { 4291 {
4263 if ((ops) && (ops->alloc)) 4292 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4264 tmem->memory = ops->alloc(ops, tmem->desc); 4293 return EINA_FALSE;
4265 else 4294 }
4266 tmem->memory = malloc(tmem->desc->size);
4267 4295
4268 if (!tmem->memory) 4296 itr = tmem->desc->members;
4269 { 4297 if (tmem->desc->member_count > 0)
4270 eina_error_set(EINA_ERROR_OUT_OF_MEMORY); 4298 {
4271 return EINA_FALSE; 4299 const Eina_Value_Struct_Member *itr_end;
4272 } 4300 itr_end = itr + tmem->desc->member_count;
4301 for (; itr < itr_end; itr++)
4302 if (!_eina_value_type_struct_setup_member(itr, tmem))
4303 goto error;
4304 }
4305 else
4306 {
4307 for (; itr->name != NULL; itr++)
4308 if (!_eina_value_type_struct_setup_member(itr, tmem))
4309 goto error;
4273 } 4310 }
4274 4311
4275 eina_error_set(0); 4312 eina_error_set(0);
4276 return EINA_TRUE; 4313 return EINA_TRUE;
4314
4315 error:
4316 itr--;
4317 for (; itr >= tmem->desc->members; itr--)
4318 _eina_value_type_struct_flush_member(itr, tmem);
4319
4320 if ((ops) && (ops->free))
4321 ops->free(ops, tmem->desc, tmem->memory);
4322 else
4323 free(tmem->memory);
4324 return EINA_FALSE;
4277} 4325}
4278 4326
4279static Eina_Bool 4327static Eina_Bool