Commit e81681d7 authored by Pekka Pessi's avatar Pekka Pessi

su_home_check_alloc(): added

darcs-hash:20080521144252-db55f-5d6d599e5b1f5b38c65ce7d91cef98d985244aa5.gz
parent b4b5840f
......@@ -103,6 +103,8 @@ SU_DLL int su_home_has_parent(su_home_t const *home);
SU_DLL void su_home_check(su_home_t const *home);
SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data);
SU_DLL int su_home_mutex_lock(su_home_t *home);
SU_DLL int su_home_mutex_unlock(su_home_t *home);
......
......@@ -283,7 +283,7 @@ size_t su_block_find_collision, su_block_find_collision_used,
su_block_find_collision_size;
#endif
su_inline su_alloc_t *su_block_find(su_block_t *b, void const *p)
su_inline su_alloc_t *su_block_find(su_block_t const *b, void const *p)
{
size_t h, h0, probe;
......@@ -306,8 +306,10 @@ su_inline su_alloc_t *su_block_find(su_block_t *b, void const *p)
probe = (b->sub_n > SUB_P) ? SUB_P : 1;
do {
if (b->sub_nodes[h].sua_data == p)
return &b->sub_nodes[h];
if (b->sub_nodes[h].sua_data == p) {
su_alloc_t const *retval = &b->sub_nodes[h];
return (su_alloc_t *)retval; /* discard const */
}
h += probe;
if (h >= b->sub_n)
h -= b->sub_n;
......@@ -463,7 +465,7 @@ void *sub_alloc(su_home_t *home,
home->suh_blocks = b2;
if (sub && !sub->sub_auto)
safefree(sub);
free(sub);
sub = b2;
}
......@@ -836,6 +838,27 @@ void su_free(su_home_t *home, void *data)
safefree(data);
}
/** Check if pointer has been allocated through home.
*
* @param home pointer to a memory home
* @param data pointer to a memory area possibly allocated though home
*/
int su_home_check_alloc(su_home_t const *home, void const *data)
{
int retval = 0;
if (home && data) {
su_block_t const *sub = MEMLOCK(home);
su_alloc_t *allocation = su_block_find(sub, data);
retval = allocation != NULL;
UNLOCK(home);
}
return retval;
}
/** Check home consistency.
*
* Ensures that the home structure and all memory blocks allocated through
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment