forked from enlightenment/efl
eina: make eina_cow_free reset the pointer to the default read only value.
This commit is contained in:
parent
05e17cb6b6
commit
613947ac0d
|
@ -78,7 +78,7 @@ struct _Eina_Cow_GC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Eina_Cow_Ptr *ref;
|
Eina_Cow_Ptr *ref;
|
||||||
const void * const *dst;
|
const void **dst;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _Eina_Cow
|
struct _Eina_Cow
|
||||||
|
@ -228,7 +228,7 @@ _eina_cow_togc_del(Eina_Cow *cow, Eina_Cow_Ptr *ref)
|
||||||
static void
|
static void
|
||||||
_eina_cow_togc_add(Eina_Cow *cow,
|
_eina_cow_togc_add(Eina_Cow *cow,
|
||||||
Eina_Cow_Ptr *ref,
|
Eina_Cow_Ptr *ref,
|
||||||
const Eina_Cow_Data * const * dst)
|
const Eina_Cow_Data ** dst)
|
||||||
{
|
{
|
||||||
Eina_Cow_GC *gc;
|
Eina_Cow_GC *gc;
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ _eina_cow_togc_add(Eina_Cow *cow,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
|
_eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
|
||||||
const Eina_Cow_Data * const *dst,
|
const Eina_Cow_Data **dst,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
void *match;
|
void *match;
|
||||||
|
@ -270,10 +270,10 @@ _eina_cow_gc(Eina_Cow *cow, Eina_Cow_Ptr *ref,
|
||||||
#ifndef NVALGRIND
|
#ifndef NVALGRIND
|
||||||
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
|
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
|
||||||
#endif
|
#endif
|
||||||
*((void**)dst) = match;
|
|
||||||
ref->refcount++;
|
ref->refcount++;
|
||||||
|
|
||||||
eina_cow_free(cow, data);
|
eina_cow_free(cow, dst);
|
||||||
|
*dst = match;
|
||||||
|
|
||||||
#ifndef NVALGRIND
|
#ifndef NVALGRIND
|
||||||
VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref));
|
VALGRIND_MAKE_MEM_NOACCESS(ref, sizeof (*ref));
|
||||||
|
@ -413,7 +413,7 @@ eina_cow_alloc(Eina_Cow *cow)
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
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_Ptr *ref;
|
||||||
|
|
||||||
|
@ -421,15 +421,17 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
|
||||||
EINA_COW_MAGIC_CHECK(cow);
|
EINA_COW_MAGIC_CHECK(cow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!data) return;
|
if (!data || !*data) return;
|
||||||
if (cow->default_value == data) return;
|
if (cow->default_value == *data) return;
|
||||||
|
|
||||||
ref = EINA_COW_PTR_GET(data);
|
ref = EINA_COW_PTR_GET(*data);
|
||||||
#ifndef NVALGRIND
|
#ifndef NVALGRIND
|
||||||
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
|
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
|
||||||
#endif
|
#endif
|
||||||
ref->refcount--;
|
ref->refcount--;
|
||||||
|
|
||||||
|
*data = (Eina_Cow_Data*) cow->default_value;
|
||||||
|
|
||||||
if (ref->refcount > 0)
|
if (ref->refcount > 0)
|
||||||
{
|
{
|
||||||
#ifndef NVALGRIND
|
#ifndef NVALGRIND
|
||||||
|
@ -441,7 +443,7 @@ eina_cow_free(Eina_Cow *cow, const Eina_Cow_Data *data)
|
||||||
#ifdef EINA_COW_MAGIC_ON
|
#ifdef EINA_COW_MAGIC_ON
|
||||||
EINA_MAGIC_SET(ref, EINA_MAGIC_NONE);
|
EINA_MAGIC_SET(ref, EINA_MAGIC_NONE);
|
||||||
#endif
|
#endif
|
||||||
_eina_cow_hash_del(cow, data, ref);
|
_eina_cow_hash_del(cow, *data, ref);
|
||||||
_eina_cow_togc_del(cow, ref);
|
_eina_cow_togc_del(cow, ref);
|
||||||
eina_mempool_free(cow->pool, (void*) 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));
|
VALGRIND_MAKE_MEM_DEFINED(ref, sizeof (*ref));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_eina_cow_togc_add(cow, ref, dst);
|
_eina_cow_togc_add(cow, ref, (const Eina_Cow_Data **) dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
|
@ -590,7 +592,7 @@ eina_cow_memcpy(Eina_Cow *cow,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_cow_free(cow, *dst);
|
eina_cow_free(cow, (const Eina_Cow_Data**) dst);
|
||||||
|
|
||||||
*((const void**)dst) = src;
|
*((const void**)dst) = src;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* @brief Free a pointer from the pool.
|
||||||
* @param cow The pool to gave back memory to.
|
* @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.
|
* @brief Get a writable pointer from a const pointer.
|
||||||
|
|
Loading…
Reference in New Issue