#endif
Eina_Cow_Ptr *ref;
- const void * const *dst;
+ const void **dst;
};
struct _Eina_Cow
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;
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;
#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));
}
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;
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
#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);
}
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
#endif
}
- eina_cow_free(cow, *dst);
+ eina_cow_free(cow, (const Eina_Cow_Data**) dst);
*((const void**)dst) = src;
}
/**
* @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.