src/mem.c: Skip dbg_*() if memory stats are disabled
These functions only need to be compiled if calcurse is built with "--enable-memory-debug". Tell the preprocessor to strip them if memory debugging/stats are disabled. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
315b33540a
commit
674f398ee9
93
src/mem.c
93
src/mem.c
@ -41,6 +41,8 @@
|
||||
|
||||
#include "calcurse.h"
|
||||
|
||||
#ifdef CALCURSE_MEMORY_DEBUG
|
||||
|
||||
enum {
|
||||
BLK_STATE,
|
||||
BLK_SIZE,
|
||||
@ -67,49 +69,8 @@ struct mem_stats {
|
||||
|
||||
static struct mem_stats mstats;
|
||||
|
||||
#endif /* CALCURSE_MEMORY_DEBUG */
|
||||
|
||||
static unsigned
|
||||
stats_add_blk (size_t size, const char *pos)
|
||||
{
|
||||
struct mem_blk *o, **i;
|
||||
|
||||
o = malloc (sizeof (*o));
|
||||
EXIT_IF (o == NULL, _("could not allocate memory to store block info"));
|
||||
|
||||
mstats.ncall++;
|
||||
|
||||
o->pos = pos;
|
||||
o->size = (unsigned)size;
|
||||
o->next = 0;
|
||||
|
||||
for (i = &mstats.blk; *i; i = &(*i)->next)
|
||||
;
|
||||
o->id = mstats.ncall;
|
||||
*i = o;
|
||||
|
||||
return o->id;
|
||||
}
|
||||
|
||||
static void
|
||||
stats_del_blk (unsigned id)
|
||||
{
|
||||
struct mem_blk *o, **i;
|
||||
|
||||
i = &mstats.blk;
|
||||
for (o = mstats.blk; o; o = o->next)
|
||||
{
|
||||
if (o->id == id)
|
||||
{
|
||||
*i = o->next;
|
||||
free (o);
|
||||
return;
|
||||
}
|
||||
i = &o->next;
|
||||
}
|
||||
|
||||
EXIT (_("Block not found"));
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void *
|
||||
xmalloc (size_t size)
|
||||
@ -170,6 +131,51 @@ xfree (void *p)
|
||||
free (p);
|
||||
}
|
||||
|
||||
#ifdef CALCURSE_MEMORY_DEBUG
|
||||
|
||||
static unsigned
|
||||
stats_add_blk (size_t size, const char *pos)
|
||||
{
|
||||
struct mem_blk *o, **i;
|
||||
|
||||
o = malloc (sizeof (*o));
|
||||
EXIT_IF (o == NULL, _("could not allocate memory to store block info"));
|
||||
|
||||
mstats.ncall++;
|
||||
|
||||
o->pos = pos;
|
||||
o->size = (unsigned)size;
|
||||
o->next = 0;
|
||||
|
||||
for (i = &mstats.blk; *i; i = &(*i)->next)
|
||||
;
|
||||
o->id = mstats.ncall;
|
||||
*i = o;
|
||||
|
||||
return o->id;
|
||||
}
|
||||
|
||||
static void
|
||||
stats_del_blk (unsigned id)
|
||||
{
|
||||
struct mem_blk *o, **i;
|
||||
|
||||
i = &mstats.blk;
|
||||
for (o = mstats.blk; o; o = o->next)
|
||||
{
|
||||
if (o->id == id)
|
||||
{
|
||||
*i = o->next;
|
||||
free (o);
|
||||
return;
|
||||
}
|
||||
i = &o->next;
|
||||
}
|
||||
|
||||
EXIT (_("Block not found"));
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void *
|
||||
dbg_malloc (size_t size, const char *pos)
|
||||
{
|
||||
@ -278,9 +284,6 @@ dbg_free (void *ptr, const char *pos)
|
||||
mstats.nfree += size;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CALCURSE_MEMORY_DEBUG
|
||||
|
||||
static void
|
||||
dump_block_info (struct mem_blk *blk)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user