v22.2b14/
v22.2b14/Win32/
v22.2b14/compat/
v22.2b14/testsuite/
v22.2b14/testsuite/clone/
v22.2b14/testsuite/command/
v22.2b14/testsuite/data/
v22.2b14/testsuite/etc/
v22.2b14/testsuite/include/
v22.2b14/testsuite/inherit/
v22.2b14/testsuite/inherit/master/
v22.2b14/testsuite/log/
v22.2b14/testsuite/single/
v22.2b14/testsuite/single/tests/compiler/
v22.2b14/testsuite/single/tests/efuns/
v22.2b14/testsuite/single/tests/operators/
v22.2b14/testsuite/u/
v22.2b14/tmp/
/*
   wrapper functions for system malloc -- keep malloc stats.
   Truilkan@TMI - 92/04/17
*/

#define IN_MALLOC_WRAPPER
#define NO_OPCODES
#include "std.h"
#include "my_malloc.h"
#include "lpc_incl.h"
#include "comm.h"

typedef struct stats_s {
    unsigned int free_calls, alloc_calls, realloc_calls;
}       stats_t;

static stats_t stats;

void wrappedmalloc_init()
{
    stats.free_calls = 0;
    stats.alloc_calls = 0;
    stats.realloc_calls = 0;
}

INLINE void *wrappedrealloc P2(void *, ptr, int, size)
{
    stats.realloc_calls++;
    return (void *) REALLOC(ptr, size);
}

INLINE void *wrappedmalloc P1(int, size)
{
    stats.alloc_calls++;
    return (void *) MALLOC(size);
}

INLINE void *wrappedcalloc P2(int, nitems, int, size)
{
    stats.alloc_calls++;
    return (void *) CALLOC(nitems, size);
}

INLINE void wrappedfree P1(void *, ptr)
{
    stats.free_calls++;
    FREE(ptr);
}

void dump_malloc_data P1(outbuffer_t *, ob)
{
    outbuf_add(ob, "using wrapped malloc:\n\n");
    outbuf_addv(ob, "#alloc calls:     %10lu\n", stats.alloc_calls);
    outbuf_addv(ob, "#free calls:      %10lu\n", stats.free_calls);
    outbuf_addv(ob, "#alloc - #free:   %10lu\n",
		stats.alloc_calls - stats.free_calls);
    outbuf_addv(ob, "#realloc calls:   %10lu\n", stats.realloc_calls);
}