2004-05-09 Michael Poole <mdpoole@troilus.org>
[ircu2.10.12-pk.git] / ircd / ircd_alloc.c
index d3630123ffa095d6978ca01b07bb7f3517b8f6ca..51df9fef0719c13f612b9f073d7265338c0e52d7 100644 (file)
 #include "s_debug.h"
 
 #include <assert.h>
+#include <string.h>
 
-#if !defined(MDEBUG)
-/*
- * RELEASE: allocation functions
- */
+static void nomem_handler(void);
+
+/* Those ugly globals... */
+OutOfMemoryHandler noMemHandler = nomem_handler;
+void *malloc_tmp;
 
-static void nomem_handler(void)
+static void
+nomem_handler(void)
 {
+#ifdef MDEBUG
+  assert(0);
+#else
   Debug((DEBUG_FATAL, "Out of memory, exiting"));
   exit(2);
+#endif
 }
 
-static OutOfMemoryHandler noMemHandler = nomem_handler;
-
-void set_nomem_handler(OutOfMemoryHandler handler)
+void
+set_nomem_handler(OutOfMemoryHandler handler)
 {
   noMemHandler = handler;
 }
 
-void* MyMalloc(size_t size)
+void* DoMalloc(size_t size, const char* x, const char* y, int z)
 {
-  void* p = malloc(size);
-  if (!p)
+  void* t = malloc(size);
+  if (!t)
     (*noMemHandler)();
-  return p;
+  return t;
 }
 
-void* MyRealloc(void* p, size_t size)
+void* DoMallocZero(size_t size, const char* x, const char* y, int z)
 {
-  void* x = realloc(p, size);
-  if (!x)
+  void* t = malloc(size);
+  if (!t)
     (*noMemHandler)();
-  return x;
+  memset(t, 0, size);
+  return t;
 }
 
-void* MyCalloc(size_t nelem, size_t size)
+void* DoRealloc(void *orig, size_t size, const char *file, int line)
 {
-  void* p = calloc(nelem, size);
-  if (!p)
+  void* t = realloc(orig, size);
+  if (!t)
     (*noMemHandler)();
-  return p;
+  return t;
 }
-
-#else /* defined(MDEBUG) */
-/*
- * DEBUG: allocation functions
- */
-void set_nomem_handler(OutOfMemoryHandler handler)
-{
-  assert(0 != handler);
-  fda_set_nomem_handler(handler);
-}
-
-#endif /* defined(MDEBUG) */
-