summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-11-04 12:45:25 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-11-04 12:45:25 +0900
commit613947ac0df4205e197e0e129ff96f5cb83c707e (patch)
tree79e16f838d0bb64d760032165360c4236f9bac79 /src/lib
parent05e17cb6b61d47897e8f019576cf7891aba97701 (diff)
eina: make eina_cow_free reset the pointer to the default read only value.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eina/eina_cow.c26
-rw-r--r--src/lib/eina/eina_cow.h6
2 files changed, 19 insertions, 13 deletions
diff --git a/src/lib/eina/eina_cow.c b/src/lib/eina/eina_cow.c
index 64c1b3fb75..a2c4e3fbfe 100644
--- a/src/lib/eina/eina_cow.c
+++ b/src/lib/eina/eina_cow.c
@@ -78,7 +78,7 @@ struct _Eina_Cow_GC
78#endif 78#endif
79 79
80 Eina_Cow_Ptr *ref; 80 Eina_Cow_Ptr *ref;
81 const void * const *dst; 81 const void **dst;
82}; 82};
83 83
84struct _Eina_Cow 84struct _Eina_Cow
@@ -228,7 +228,7 @@ _eina_cow_togc_del(Eina_Cow *cow, Eina_Cow_Ptr *ref)
228static void 228static void
229_eina_cow_togc_add(Eina_Cow *cow, 229_eina_cow_togc_add(Eina_Cow *cow,
230 Eina_Cow_Ptr *ref, 230 Eina_Cow_Ptr *ref,
231 const Eina_Cow_Data * const * dst) 231 const Eina_Cow_Data ** dst)
232{ 232{
233 Eina_Cow_GC *gc; 233 Eina_Cow_GC *gc;
234 234
@@ -255,7 +255,7 @@ _eina_cow_togc_add(Eina_Cow *cow,
255 255
256static void 256static void
257_eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref, 257_eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
258 const Eina_Cow_Data * const *dst, 258 const Eina_Cow_Data **dst,
259 void *data) 259 void *data)
260{ 260{
261 void *match; 261 void *match;
@@ -270,10 +270,10 @@ _eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
270#ifndef NVALGRIND 270#ifndef NVALGRIND
271 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref)); 271 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
272#endif 272#endif
273 *((void**)dst) = match;
274 ref->refcount++; 273 ref->refcount++;
275 274
276 eina_cow_free(cow, data); 275 eina_cow_free(cow, dst);
276 *dst = match;
277 277
278#ifndef NVALGRIND 278#ifndef NVALGRIND
279 VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref)); 279 VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref));
@@ -413,7 +413,7 @@ eina_cow_alloc(Eina_Cow *cow)
413} 413}
414 414
415EAPI void 415EAPI void
416eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data) 416eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data **data)
417{ 417{
418 Eina_Cow_Ptr *ref; 418 Eina_Cow_Ptr *ref;
419 419
@@ -421,15 +421,17 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
421 EINA_COW_MAGIC_CHECK(cow); 421 EINA_COW_MAGIC_CHECK(cow);
422#endif 422#endif
423 423
424 if (!data) return; 424 if (!data || !*data) return;
425 if (cow->default_value == data) return; 425 if (cow->default_value == *data) return;
426 426
427 ref = EINA_COW_PTR_GET(data); 427 ref = EINA_COW_PTR_GET(*data);
428#ifndef NVALGRIND 428#ifndef NVALGRIND
429 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref)); 429 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
430#endif 430#endif
431 ref->refcount--; 431 ref->refcount--;
432 432
433 *data = (Eina_Cow_Data*) cow->default_value;
434
433 if (ref->refcount > 0) 435 if (ref->refcount > 0)
434 { 436 {
435#ifndef NVALGRIND 437#ifndef NVALGRIND
@@ -441,7 +443,7 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
441#ifdef EINA_COW_MAGIC_ON 443#ifdef EINA_COW_MAGIC_ON
442 EINA_MAGIC_SET(ref, EINA_MAGIC_NONE); 444 EINA_MAGIC_SET(ref, EINA_MAGIC_NONE);
443#endif 445#endif
444 _eina_cow_hash_del(cow, data, ref); 446 _eina_cow_hash_del(cow, *data, ref);
445 _eina_cow_togc_del(cow, ref); 447 _eina_cow_togc_del(cow, ref);
446 eina_mempool_free(cow->pool, (void*) ref); 448 eina_mempool_free(cow->pool, (void*) ref);
447} 449}
@@ -558,7 +560,7 @@ eina_cow_done(Eina_Cow *cow,
558 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref)); 560 VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
559#endif 561#endif
560 562
561 _eina_cow_togc_add(cow, ref, dst); 563 _eina_cow_togc_add(cow, ref, (const Eina_Cow_Data **) dst);
562} 564}
563 565
564EAPI void 566EAPI void
@@ -590,7 +592,7 @@ eina_cow_memcpy(Eina_Cow *cow,
590#endif 592#endif
591 } 593 }
592 594
593 eina_cow_free(cow, *dst); 595 eina_cow_free(cow, (const Eina_Cow_Data**) dst);
594 596
595 *((const void**)dst) = src; 597 *((const void**)dst) = src;
596} 598}
diff --git a/src/lib/eina/eina_cow.h b/src/lib/eina/eina_cow.h
index 875e1fea55..10cb34d28d 100644
--- a/src/lib/eina/eina_cow.h
+++ b/src/lib/eina/eina_cow.h
@@ -79,8 +79,12 @@ EAPI const Eina_Cow_Data *eina_cow_alloc(Eina_Cow *cow) EINA_WARN_UNUSED_RESULT;
79/** 79/**
80 * @brief Free a pointer from the pool. 80 * @brief Free a pointer from the pool.
81 * @param cow The pool to gave back memory to. 81 * @param cow The pool to gave back memory to.
82 * @param data The data to give back.
83 *
84 * @note To simplify the caller code *data will point to the default
85 * read only state after the call to this function.
82 */ 86 */
83EAPI void eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data); 87EAPI void eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data **data);
84 88
85/** 89/**
86 * @brief Get a writable pointer from a const pointer. 90 * @brief Get a writable pointer from a const pointer.