ldmud-3.2.9/doc/
ldmud-3.2.9/doc/efun/
ldmud-3.2.9/mud/
ldmud-3.2.9/mud/heaven7/
ldmud-3.2.9/mud/heaven7/lib/
ldmud-3.2.9/mud/lp-245/
ldmud-3.2.9/mud/lp-245/banish/
ldmud-3.2.9/mud/lp-245/doc/
ldmud-3.2.9/mud/lp-245/doc/examples/
ldmud-3.2.9/mud/lp-245/doc/sefun/
ldmud-3.2.9/mud/lp-245/log/
ldmud-3.2.9/mud/lp-245/obj/Go/
ldmud-3.2.9/mud/lp-245/players/lars/
ldmud-3.2.9/mud/lp-245/room/death/
ldmud-3.2.9/mud/lp-245/room/maze1/
ldmud-3.2.9/mud/lp-245/room/sub/
ldmud-3.2.9/mud/lp-245/secure/
ldmud-3.2.9/mud/morgengrauen/
ldmud-3.2.9/mud/morgengrauen/lib/
ldmud-3.2.9/mud/sticklib/
ldmud-3.2.9/mud/sticklib/src/
ldmud-3.2.9/mudlib/uni-crasher/
ldmud-3.2.9/pkg/
ldmud-3.2.9/pkg/debugger/
ldmud-3.2.9/pkg/diff/
ldmud-3.2.9/pkg/misc/
ldmud-3.2.9/src/autoconf/
ldmud-3.2.9/src/bugs/
ldmud-3.2.9/src/bugs/MudCompress/
ldmud-3.2.9/src/bugs/b-020916-files/
ldmud-3.2.9/src/bugs/doomdark/
ldmud-3.2.9/src/bugs/ferrycode/ferry/
ldmud-3.2.9/src/bugs/ferrycode/obj/
ldmud-3.2.9/src/bugs/psql/
ldmud-3.2.9/src/done/
ldmud-3.2.9/src/done/order_alist/
ldmud-3.2.9/src/done/order_alist/obj/
ldmud-3.2.9/src/done/order_alist/room/
ldmud-3.2.9/src/gcc/
ldmud-3.2.9/src/gcc/2.7.0/
ldmud-3.2.9/src/gcc/2.7.1/
ldmud-3.2.9/src/hosts/
ldmud-3.2.9/src/hosts/GnuWin32/
ldmud-3.2.9/src/hosts/amiga/NetIncl/
ldmud-3.2.9/src/hosts/amiga/NetIncl/netinet/
ldmud-3.2.9/src/hosts/amiga/NetIncl/sys/
ldmud-3.2.9/src/hosts/i386/
ldmud-3.2.9/src/hosts/msdos/byacc/
ldmud-3.2.9/src/hosts/msdos/doc/
ldmud-3.2.9/src/hosts/os2/
ldmud-3.2.9/src/hosts/win32/
ldmud-3.2.9/src/util/
ldmud-3.2.9/src/util/erq/
ldmud-3.2.9/src/util/indent/hosts/next/
ldmud-3.2.9/src/util/xerq/
ldmud-3.2.9/src/util/xerq/lpc/
ldmud-3.2.9/src/util/xerq/lpc/www/
#ifndef __XALLOC_H__
#define __XALLOC_H__ 1

#include "driver.h"

/* --- Macros --- */

/* void xallocate(void * dest, size_t size, const char * txt)
 *   Allocate <size> bytes using xalloc() and assign the pointer to <dest>.
 *   If the memory can't be allocated, call error() using an error message
 *   containing the description <txt>
 */

#define xallocate(dest,size,txt) \
    if (NULL == ((dest) = xalloc(size))) {\
        error("(%s:%d) Out of memory (%lu bytes) for %s\n"\
             , __FILE__, __LINE__, (unsigned long)(size), txt); \
    } else {}


/* void outofmem(const char * txt)
 *   Throw an 'out of memory' error for an allocation of unknown size with the
 *   description <txt>.
 */

#define outofmemory(txt) \
    error("(%s:%d) Out of memory for %s\n", __FILE__, __LINE__, txt)

/* void outofmem(size_t size, const char * txt)
 *   Throw an 'out of memory' error for an allocation of <size> with the
 *   description <txt>.
 */

#define outofmem(size,txt) \
    error("(%s:%d) Out of memory (%lu bytes) for %s\n"\
         , __FILE__, __LINE__, (unsigned long)(size), txt)

/* --- Constants --- */

/* Allocation privilege levels */

#define MALLOC_USER    (0)
#define MALLOC_MASTER  (1)
#define MALLOC_SYSTEM  (2)

/* --- Variables --- */

extern Bool out_of_memory;
extern int malloc_privilege;
extern char *reserved_user_area;
extern char *reserved_master_area;
extern char *reserved_system_area;
extern mp_int reserved_user_size;
extern mp_int reserved_master_size;
extern mp_int reserved_system_size;
extern mp_int min_malloced;
extern mp_int min_small_malloced;
extern mp_int max_malloced;
extern int stack_direction;


/* --- SMalloc --- */

#ifdef MALLOC_smalloc

#if defined(MALLOC_TRACE)

#define xalloc_traced(size,  file, line) smalloc((size), (file), (line))
#define xalloc(size) (smalloc((size), __FILE__, __LINE__))

extern POINTER smalloc(size_t, const char *, int) MALLOC;

#define string_copy_traced(s, file, line) (smalloc_string_copy(s, file, line))
#define string_copy(s) (smalloc_string_copy(s, __FILE__ "::string_copy", __LINE__))
extern char * smalloc_string_copy(const char *, const char *, int) MALLOC;

#else

#define xalloc_traced(size,  file, line) smalloc((size))
#define xalloc(size) (smalloc((size)))
extern POINTER smalloc(size_t) MALLOC;

#endif

extern POINTER rexalloc(POINTER, size_t);
extern POINTER amalloc(size_t) MALLOC;
extern POINTER pxalloc(size_t) MALLOC;
extern void xfree(POINTER);
extern void pfree(POINTER);
extern void afree(POINTER);

#endif /* MALLOC_smalloc */


/* --- System malloc() --- */

#ifdef MALLOC_sysmalloc

#include <stdlib.h>

extern POINTER xalloc(size_t size) MALLOC;

#if defined(MALLOC_TRACE)
#  define xalloc_traced(size,  file, line) xalloc((size))
#else
#  define xalloc_traced(size,  file, line) xalloc((size))
#endif

#define xfree    free
#define rexalloc realloc
#define amalloc  xalloc
#define pxalloc  xalloc
#define afree    free
#define pfree    free

#endif /* MALLOC_sysmalloc */


/* --- Associated functions --- */

extern void get_stack_direction (void);
extern void assert_stack_gap(void);
extern void reserve_memory (void);
extern void dump_lpc_trace (int d, void *p);
extern void dump_malloc_trace (int d, void *adr);


#ifndef string_copy

#define string_copy_traced(s, file, line) string_copy(s)
extern char * string_copy(const char *str) MALLOC;

#endif

#endif /* XALLOC_H__ */