#ifndef EXTERN_SAFEMALLOC_H
#define EXTERN_SAFEMALLOC_H

#define TMP_MALLOC_PARAMS unsigned int, const char *, unsigned int

extern void *safemalloc(size_t, TMP_MALLOC_PARAMS);
extern void *safecalloc(size_t, size_t, TMP_MALLOC_PARAMS);
extern void safefree(void *, TMP_MALLOC_PARAMS);


/* which malloc routines to use --
 note realloc isn't done yet as we don't use it atm */
#define MALLOC(x)    safemalloc(x, MALLOC_UNDEFINED, __FILE__, __LINE__)
#define CALLOC(x, y) safecalloc(x, y, MALLOC_UNDEFINED, __FILE__, __LINE__)
#define FREE(x)      safefree(x, MALLOC_UNDEFINED, __FILE__, __LINE__)

#define XMALLOC(x, X)    safemalloc(x, X, __FILE__, __LINE__)
#define XCALLOC(x, y, X) safecalloc(x, y, X, __FILE__, __LINE__)
#define XFREE(x, X)      safefree(x, X, __FILE__, __LINE__)

/* now the functions that may or may not be used */
#ifdef EXTRA_MALLOC_WRAPPER
# ifdef USE_POINTER_COMPARES
extern int malloc_valid(const void *, size_t, TMP_MALLOC_PARAMS);
#  define MALLOC_VALID(x, y, z) malloc_valid(x, y, z, __FILE__, __LINE__)
#  define PTR_LESS(x, y) ((unsigned long int)x < (unsigned long int)y)
#  define PTR_EQUAL(x, y) ((unsigned long int)x == (unsigned long int)y)
#  define PTR_MORE(x, y) ((unsigned long int)x > (unsigned long int)y)
#  define PTR_DIFF(x, y) ((unsigned long int)x - (unsigned long int)y)
# else
#  define MALLOC_VALID(x, y, z) (x ? TRUE : FALSE)
#  ifndef NWARNS
#   warning Malloc valid reduced in strength
#  endif
# endif
extern void malloc_no_members(TMP_MALLOC_PARAMS);
# define MALLOC_NO_MEMBERS(x) malloc_no_members(x, __FILE__, __LINE__)
#else
# define MALLOC_NO_MEMBERS(x) (TRUE)
# define MALLOC_VALID(x, y, z) (x ? TRUE : FALSE)
# ifndef NWARNS
#  warning Malloc valid reduced in strength
#  warning Malloc no members removed
# endif
#endif


#undef TMP_MALLOC_PARAMS /* used above above, ONLY */

#ifdef TALKER_MAIN_H
/* user command */
extern void malloc_count_show(player *, char *);
#endif

#endif
