Commit b8fddfdd authored by Pekka Pessi's avatar Pekka Pessi

su: added function su_in_home()

darcs-hash:20061110113826-65a35-6f191ada713c5c332a1fbc9ffb702b83676fb4f8.gz
parent f54612b6
......@@ -115,6 +115,8 @@ SU_DLL void *su_salloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_realloc(su_home_t *h, void *data, isize_t size)
__attribute__((__malloc__));
SU_DLL int su_in_home(su_home_t *h, void const *data)
__attribute__((__malloc__));
SU_DLL char *su_strdup(su_home_t *home, char const *s)
__attribute__((__malloc__));
......
......@@ -266,7 +266,7 @@ size_t su_block_find_collision, su_block_find_collision_used,
su_block_find_collision_size;
#endif
static inline su_alloc_t *su_block_find(su_block_t *b, void *p)
static inline su_alloc_t *su_block_find(su_block_t *b, void const *p)
{
size_t h, h0, probe;
......@@ -854,7 +854,7 @@ void su_home_check_blocks(su_block_t const *b)
* NULL upon an error.
*
* @deprecated
* Use su_home_clone() instead of su_home_create().
* Use su_home_new() or su_home_clone() instead of su_home_create().
*/
su_home_t *su_home_create(void)
{
......@@ -1288,6 +1288,39 @@ void *su_realloc(su_home_t *home, void *data, isize_t size)
}
/**Check if a memory block has been allocated from the @a home.
*
* Check if the given memory block has been allocated from the home.
*
* @param home pointer to memory pool object
* @param memory ponter to memory block
*
* @retval 1 if @a memory has been allocated from @a home.
* @retval 0 otherwise
*/
int su_in_home(su_home_t *home, void const *memory)
{
su_alloc_t *sua;
su_block_t *sub;
int retval = 0;
if (!home || !memory)
return 0;
sub = MEMLOCK(home);
if (sub) {
sua = su_block_find(sub, memory);
retval = su_alloc_check(sub, sua);
UNLOCK(home);
}
return retval;
}
/**Allocate and zero a memory block.
*
* The function su_zalloc() allocates a memory block with a given size from
......
......@@ -122,6 +122,13 @@ static int test_alloc(void)
TEST_1(m = su_zalloc(h2->home, 20));
TEST_1(su_in_home(h2->home, m));
TEST_1(!su_in_home(h2->home, (char *)m + 1));
TEST_1(!su_in_home(h2->home, su_in_home));
TEST_1(!su_in_home(h3->home, m));
TEST_1(!su_in_home(NULL, m));
TEST_1(!su_in_home(h3->home, NULL));
TEST(su_home_move(home, NULL), 0);
TEST(su_home_move(NULL, home), 0);
TEST(su_home_move(home, h3->home), 0);
......
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