typedef void (*OutOfMemoryHandler)(void);
extern void set_nomem_handler(OutOfMemoryHandler handler);
-#if !defined(MDEBUG)
-/*
- * RELEASE: allocation functions
- */
+/* The mappings for the My* functions... */
+#define MyMalloc(size) \
+ DoMalloc(size, "malloc", __FILE__, __LINE__)
+
+#define MyCalloc(nelem, size) \
+ DoMallocZero(size * nelem, "calloc", __FILE__, __LINE__)
+
+#define MyFree(p) \
+ if (p) \
+ DoFree(p, __FILE__, __LINE__)
+
+#define MyRealloc(p, size) \
+ DoRealloc(p, size, __FILE__, __LINE__)
+
+/* First version: fast non-debugging macros... */
+#ifndef MDEBUG
#ifndef INCLUDED_stdlib_h
-#include <stdlib.h> /* free */
+#include <stdlib.h> /* free */
#define INCLUDED_stdlib_h
#endif
-#define MyFree(x) do { free((x)); (x) = 0; } while(0)
+extern OutOfMemoryHandler noMemHandler;
-extern void* MyMalloc(size_t size);
-extern void* MyCalloc(size_t nelem, size_t size);
-extern void* MyRealloc(void* p, size_t size);
+#define DoFree(x, file, line) do { free((x)); (x) = 0; } while(0)
+extern void* DoMalloc(size_t len, const char*, const char*, int);
+extern void* DoMallocZero(size_t len, const char*, const char*, int);
+extern void *DoRealloc(void *, size_t, const char*, int);
+/* Second version: slower debugging versions... */
#else /* defined(MDEBUG) */
-/*
- * DEBUG: allocation functions
- */
-#ifndef INCLUDED_fda_h
-#include "fda.h"
-#endif
-
-#define MyMalloc(s) fda_malloc((s), __FILE__, __LINE__)
-#define MyCalloc(n, s) fda_calloc((n), (s), __FILE__, __LINE__)
-#define MyFree(p) fda_free((p))
-#define MyRealloc(p, s) fda_realloc((p), (s), __FILE__, __LINE__)
+#include <sys/types.h>
+#include "memdebug.h"
+#define DoMalloc(size, type, file, line) \
+ dbg_malloc(size, type, file, line)
+#define DoMallocZero(size, type, file, line) \
+ dbg_malloc_zero(size, type, file, line)
+#define DoFree(p, file, line) \
+ dbg_free(p, file, line)
+#define DoRealloc(p, size, file, line) \
+ dbg_realloc(p, size, file, line)
#endif /* defined(MDEBUG) */
#endif /* INCLUDED_ircd_alloc_h */
-