/*
To use dmalloc, define in your make file or build settings
	USE_DMALLOC
and include this header file:
	#include <dmalloc.h>

And add a call to 
	d_check()
before exiting your program.

You DO NOT need to use the d_*() functions in your source, you should use
malloc,free etc as normal it's all done with defines so you don't need to
modify code.

Call
	d_malloc_init(imsg); before calling any other dmalloc functions.



  	d_memory_limit(30000000);	Optional defaults to no limit
	
Currently you need to link in the treading and emsg sams, this is a fault
and will be fixed when I have a moment and figure out how.


*/
#ifndef DONE_DMALLOC
#define DONE_DMALLOC 1

#ifdef USE_DMALLOC


#	ifdef MEMORY_LIMIT

		void d_memory_limit(unsigned long size);

		unsigned long d_memory_peak(void);

#	endif




#ifdef USE_DMALLOC_CHECKED
#define malloc(x) d_malloc_checked(x,__FILE__,__LINE__)
#else
#define malloc(x) d_malloc(x,__FILE__,__LINE__)
#endif

#define calloc(x,y) d_calloc(x,y,__FILE__,__LINE__)
#define free(x) {d_free(x,__FILE__,__LINE__);x=NULL;}
#define strdup(x) d_strdup(x,__FILE__,__LINE__)
#define realloc(x,sz) d_realloc(x,sz,__FILE__,__LINE__)
#define guard_test() d_guard_test(__FILE__,__LINE__)
#else
#define free(x) {real_free(x);x=NULL;}
#define malloc(x) real_malloc(x)
#endif
int d_malloc_list_using(void);
void d_set_abort(void (*fn)(int x));
int d_check_pointer(char *point, char *src, int line);

int d_log_big(char *fname);
void *d_calloc( size_t num, size_t size , char *fname, int line);
void *d_malloc(int sz, char *file, int line);
void d_free(void *x, char *file, int line);
char *d_strdup(const char *s, char *file, int line);
char *real_strdup(const char *s);
void d_check(void);
void *d_realloc(void *x, int sz, char *file, int line);
void *real_calloc(int num, int size);
void real_free(void *x);
void *real_malloc(int size);
void *real_realloc(void *x, int sz);
void d_malloc_init(int (*vemsg)(const char * arg_list, ...));
void d_malloc_exit(void);
int d_guard_test(char *file, int line);
int d_free_idle(void);
int d_free_check(void);
char * d_info(char *info);
void *d_malloc_checked(int sz, char* file, int line);
void d_set_nshow(int n);
void d_dump(void);
void d_malloc_checkone(void *x, char *reason);
int d_free_checklist(void);
void d_set_die(int (*my_die_fn)(char *reason)) ;
int d_free_set_big(int x);
void dmalloc_set_emsg(int (*vemsg)(const char * arg_list, ...));
void dmalloc_set_dump(int xdump_to_stdout, int xdump_to_emsg);
void dmalloc_ignore_leak_do(char *file, int line);
#define dmalloc_ignore_leak() dmalloc_ignore_leak_do(__FILE__,__LINE__)
int d_nused(void);

void d_mutex_wait(int line);

void simple_free(void *x, char *src, int line);
void *simple_malloc(int n);
void *simple_realloc(void *x, int sz);
void *simple_calloc(int num, int size);
char *simple_strdup(const char *s);

#endif
