diff dmd/mem.c @ 268:23d0d9855cad trunk

[svn r289] Fixed: right shift >> was broken for unsigned types. Fixed: debug info for classes now started.
author lindquist
date Sun, 15 Jun 2008 18:52:27 +0200
parents 35d93ce68cf4
children 967178e31a13
line wrap: on
line diff
--- a/dmd/mem.c	Sun Jun 15 18:37:23 2008 +0200
+++ b/dmd/mem.c	Sun Jun 15 18:52:27 2008 +0200
@@ -2,19 +2,27 @@
 /* Copyright (c) 2000 Digital Mars	*/
 /* All Rights Reserved 			*/
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-// I needed to perfix the dir after upgrading to gc 7.0
-#include "gc/gc.h"
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cassert>
 
 #include "mem.h"
 
+#define USE_BOEHM_GC    0
+
+#if USE_BOEHM_GC
+    // I needed to perfix the dir after upgrading to gc 7.0
+    #include "gc/gc.h"
+#endif
+
 /* This implementation of the storage allocator uses the standard C allocation package.
  */
 
 Mem mem;
+
+#if USE_BOEHM_GC
+
 static bool gc_was_init = false;
 
 void Mem::init()
@@ -148,4 +156,112 @@
     GC_free(p);
 }
 
+#elif !USE_BOEHM_GC
 
+void Mem::init()
+{
+}
+
+char *Mem::strdup(const char *s)
+{
+    char *p;
+
+    if (s)
+    {
+    p = ::strdup(s);
+    if (p)
+        return p;
+    error();
+    }
+    return NULL;
+}
+
+void *Mem::malloc(size_t size)
+{   void *p;
+
+    if (!size)
+    p = NULL;
+    else
+    {
+    p = ::malloc(size);
+    if (!p)
+        error();
+    }
+    return p;
+}
+
+void *Mem::calloc(size_t size, size_t n)
+{   void *p;
+
+    if (!size || !n)
+    p = NULL;
+    else
+    {
+    p = ::malloc(size * n);
+    if (!p)
+        error();
+        memset(p, 0, size * n);
+    }
+    return p;
+}
+
+void *Mem::realloc(void *p, size_t size)
+{
+    if (!size)
+    {   if (p)
+    {   ::free(p);
+        p = NULL;
+    }
+    }
+    else if (!p)
+    {
+    p = ::malloc(size);
+    if (!p)
+        error();
+    }
+    else
+    {
+    p = ::realloc(p, size);
+    if (!p)
+        error();
+    }
+    return p;
+}
+
+void Mem::free(void *p)
+{
+    if (p)
+        ::free(p);
+}
+
+void *Mem::mallocdup(void *o, size_t size)
+{   void *p;
+
+    if (!size)
+        p = NULL;
+    else
+    {
+        p = ::malloc(size);
+        if (!p)
+            error();
+        else
+            memcpy(p,o,size);
+    }
+    return p;
+}
+
+void Mem::error()
+{
+    printf("Error: out of memory\n");
+    exit(EXIT_FAILURE);
+}
+
+void Mem::fullcollect()
+{
+}
+
+void Mem::mark(void *pointer)
+{
+}
+
+#endif // USE_BOEHM_GC