chiark / gitweb /
missing samples_written assign
[disorder] / lib / mem.c
index 07c3495e2d656ea7df77a5325e97ae3b3e8edd9a..c2dd40cf6baf13b9d11099fd02f455bcbdbae32e 100644 (file)
--- a/lib/mem.c
+++ b/lib/mem.c
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2006 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <config.h>
 #include "types.h"
 
+#if GC
 #include <gc.h>
+#endif
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
 
 #include "mem.h"
 #include "log.h"
 
 #include "disorder.h"
 
-static void *(*do_malloc)(size_t) = GC_malloc;
-static void *(*do_realloc)(void *, size_t) = GC_realloc;
-static void *(*do_malloc_atomic)(size_t) = GC_malloc_atomic;
-static void (*do_free)(void *) = GC_free;
-
 static void *malloc_and_zero(size_t n) {
   void *ptr = malloc(n);
 
@@ -45,16 +43,32 @@ static void *malloc_and_zero(size_t n) {
   return ptr;
 }
 
-void mem_init(int gc) {
+#if GC
+static void *(*do_malloc)(size_t) = GC_malloc;
+static void *(*do_realloc)(void *, size_t) = GC_realloc;
+static void *(*do_malloc_atomic)(size_t) = GC_malloc_atomic;
+static void (*do_free)(void *) = GC_free;
+#else
+static void *(*do_malloc)(size_t) = malloc_and_zero;
+static void *(*do_realloc)(void *, size_t) = realloc;
+static void *(*do_malloc_atomic)(size_t) = malloc;
+static void (*do_free)(void *) = free;
+#endif
+
+void mem_init(void) {
+#if GC
   const char *e;
   
-  if(!gc || ((e = getenv("DISORDER_GC")) && !strcmp(e, "no"))) {
+  if(((e = getenv("DISORDER_GC")) && !strcmp(e, "no"))) {
     do_malloc = malloc_and_zero;
     do_malloc_atomic = malloc;
     do_realloc = realloc;
     do_free = free;
-  } else
+  } else {
     GC_init();
+    assert(GC_all_interior_pointers);
+  }
+#endif
 }
 
 void *xmalloc(size_t n) {
@@ -121,4 +135,3 @@ c-basic-offset:2
 comment-column:40
 End:
 */
-/* arch-tag:fceaf81fe79b2f4f87c9541774a2b8f2 */