cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=613947ac0df4205e197e0e129ff96f5cb83c707e

commit 613947ac0df4205e197e0e129ff96f5cb83c707e
Author: Cedric Bail <cedric.b...@samsung.com>
Date:   Mon Nov 4 12:45:25 2013 +0900

    eina: make eina_cow_free reset the pointer to the default read only value.
---
 src/lib/eina/eina_cow.c | 26 ++++++++++++++------------
 src/lib/eina/eina_cow.h |  6 +++++-
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/lib/eina/eina_cow.c b/src/lib/eina/eina_cow.c
index 64c1b3f..a2c4e3f 100644
--- a/src/lib/eina/eina_cow.c
+++ b/src/lib/eina/eina_cow.c
@@ -78,7 +78,7 @@ struct _Eina_Cow_GC
 #endif
 
    Eina_Cow_Ptr *ref;
-   const void * const *dst;
+   const void **dst;
 };
 
 struct _Eina_Cow
@@ -228,7 +228,7 @@ _eina_cow_togc_del(Eina_Cow *cow, Eina_Cow_Ptr *ref)
 static void
 _eina_cow_togc_add(Eina_Cow *cow,
                    Eina_Cow_Ptr *ref,
-                   const Eina_Cow_Data * const * dst)
+                   const Eina_Cow_Data ** dst)
 {
    Eina_Cow_GC *gc;
 
@@ -255,7 +255,7 @@ _eina_cow_togc_add(Eina_Cow *cow,
 
 static void
 _eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
-             const Eina_Cow_Data * const *dst,
+             const Eina_Cow_Data **dst,
              void *data)
 {
    void *match;
@@ -270,10 +270,10 @@ _eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
 #ifndef NVALGRIND
         VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
 #endif
-        *((void**)dst) = match;
         ref->refcount++;
 
-        eina_cow_free(cow, data);
+        eina_cow_free(cow, dst);
+        *dst = match;
 
 #ifndef NVALGRIND
         VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref));
@@ -413,7 +413,7 @@ eina_cow_alloc(Eina_Cow *cow)
 }
 
 EAPI void
-eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
+eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data **data)
 {
    Eina_Cow_Ptr *ref;
 
@@ -421,15 +421,17 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
    EINA_COW_MAGIC_CHECK(cow);
 #endif
 
-   if (!data) return;
-   if (cow->default_value == data) return;
+   if (!data || !*data) return;
+   if (cow->default_value == *data) return;
 
-   ref = EINA_COW_PTR_GET(data);
+   ref = EINA_COW_PTR_GET(*data);
 #ifndef NVALGRIND
    VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
 #endif
    ref->refcount--;
 
+   *data = (Eina_Cow_Data*) cow->default_value;
+
    if (ref->refcount > 0)
      {
 #ifndef NVALGRIND
@@ -441,7 +443,7 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
 #ifdef EINA_COW_MAGIC_ON
    EINA_MAGIC_SET(ref, EINA_MAGIC_NONE);
 #endif
-   _eina_cow_hash_del(cow, data, ref);
+   _eina_cow_hash_del(cow, *data, ref);
    _eina_cow_togc_del(cow, ref);
    eina_mempool_free(cow->pool, (void*) ref);
 }
@@ -558,7 +560,7 @@ eina_cow_done(Eina_Cow *cow,
    VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
 #endif
 
-   _eina_cow_togc_add(cow, ref, dst);
+   _eina_cow_togc_add(cow, ref, (const Eina_Cow_Data **) dst);
 }
 
 EAPI void
@@ -590,7 +592,7 @@ eina_cow_memcpy(Eina_Cow *cow,
 #endif
      }
 
-   eina_cow_free(cow, *dst);
+   eina_cow_free(cow, (const Eina_Cow_Data**) dst);
 
    *((const void**)dst) = src;
 }
diff --git a/src/lib/eina/eina_cow.h b/src/lib/eina/eina_cow.h
index 875e1fe..10cb34d 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;
 /**
  * @brief Free a pointer from the pool.
  * @param cow The pool to gave back memory to.
+ * @param data The data to give back.
+ *
+ * @note To simplify the caller code *data will point to the default
+ * read only state after the call to this function.
  */
-EAPI void eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data);
+EAPI void eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data **data);
 
 /**
  * @brief Get a writable pointer from a const pointer.

-- 


Reply via email to