1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

fix debug linking

This commit is contained in:
Alasdair Kergon 2005-11-10 16:33:04 +00:00
parent 0c32d9dbef
commit 91a7cf559d
2 changed files with 16 additions and 22 deletions

View File

@ -342,23 +342,26 @@ int dm_tree_node_add_target_area(struct dm_tree_node *node,
* Memory management
*******************/
void *dm_malloc_aux(size_t s, const char *file, int line);
#define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__)
char *dm_strdup(const char *str);
void *dm_malloc_aux(size_t s, const char *file, int line);
void *dm_malloc_aux_debug(size_t s, const char *file, int line);
void dm_free_aux(void *p);
void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line);
int dm_dump_memory_debug(void);
void dm_bounds_check_debug(void);
#ifdef DEBUG_MEM
void dm_free_aux(void *p);
void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line);
int dm_dump_memory(void);
void dm_bounds_check(void);
# define dm_malloc(s) dm_malloc_aux_debug((s), __FILE__, __LINE__)
# define dm_free(p) dm_free_aux(p)
# define dm_realloc(p, s) dm_realloc_aux(p, s, __FILE__, __LINE__)
# define dm_dump_memory_debug()
# define dm_bounds_check_debug()
#else
# define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__)
# define dm_free(p) free(p)
# define dm_realloc(p, s) realloc(p, s)
# define dm_dump_memory()
@ -366,6 +369,7 @@ void dm_bounds_check(void);
#endif
/*
* The pool allocator is useful when you are going to allocate
* lots of memory, use the memory for a bit, and then free the

View File

@ -28,8 +28,6 @@ char *dm_strdup(const char *str)
return ret;
}
#ifdef DEBUG_MEM
struct memblock {
struct memblock *prev, *next; /* All allocated blocks are linked */
size_t length; /* Size of the requested block */
@ -51,7 +49,7 @@ static struct {
static struct memblock *_head = 0;
static struct memblock *_tail = 0;
void *dm_malloc_aux(size_t s, const char *file, int line)
void *dm_malloc_aux_debug(size_t s, const char *file, int line)
{
struct memblock *nb;
size_t tsize = s + sizeof(*nb) + sizeof(unsigned long);
@ -72,9 +70,7 @@ void *dm_malloc_aux(size_t s, const char *file, int line)
nb->file = file;
nb->line = line;
#ifdef BOUNDS_CHECK
dm_bounds_check();
#endif
/* setup fields */
nb->magic = nb + 1;
@ -125,9 +121,7 @@ void dm_free_aux(void *p)
if (!p)
return;
#ifdef BOUNDS_CHECK
dm_bounds_check();
#endif
/* sanity check */
assert(mb->magic == p);
@ -171,7 +165,7 @@ void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line)
void *r;
struct memblock *mb = ((struct memblock *) p) - 1;
r = dm_malloc_aux(s, file, line);
r = dm_malloc_aux_debug(s, file, line);
if (p) {
memcpy(r, p, mb->length);
@ -181,7 +175,7 @@ void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line)
return r;
}
int dm_dump_memory(void)
int dm_dump_memory_debug(void)
{
unsigned long tot = 0;
struct memblock *mb;
@ -216,7 +210,7 @@ int dm_dump_memory(void)
return 1;
}
void dm_bounds_check(void)
void dm_bounds_check_debug(void)
{
struct memblock *mb = _head;
while (mb) {
@ -230,8 +224,6 @@ void dm_bounds_check(void)
}
}
#else
void *dm_malloc_aux(size_t s, const char *file, int line)
{
if (s > 50000000) {
@ -242,5 +234,3 @@ void *dm_malloc_aux(size_t s, const char *file, int line)
return malloc(s);
}
#endif