]> git.lizzy.rs Git - rust.git/commitdiff
fix track alloc code
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 13 Dec 2011 02:25:17 +0000 (18:25 -0800)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 13 Dec 2011 02:25:17 +0000 (18:25 -0800)
src/rt/memory_region.cpp
src/rt/memory_region.h

index 82821f32222e21c3d1da6493c7bea06b127f772b..42eb1c6d9acbba247caf7ef9bfcb13a3ab17d718 100644 (file)
@@ -2,7 +2,8 @@
 #include "memory_region.h"
 
 #if RUSTRT_TRACK_ALLOCATIONS >= 1
-#  define PTR_SIZE (sizeof(void*))
+// For some platforms, 16 byte alignment is required.
+#  define PTR_SIZE 16
 #  define ALIGN_PTR(x) (((x)+PTR_SIZE-1)/PTR_SIZE*PTR_SIZE)
 #  define HEADER_SIZE ALIGN_PTR(sizeof(alloc_header))
 #  define MAGIC 0xbadc0ffe
@@ -65,11 +66,15 @@ memory_region::realloc(void *mem, size_t orig_size) {
     }
 
     alloc_header *alloc = get_header(mem);
+#   if RUSTRT_TRACK_ALLOCATIONS >= 1
+    assert(alloc->magic == MAGIC);
+#   endif
+
     size_t size = orig_size + HEADER_SIZE;
     alloc_header *newMem = (alloc_header *)_srv->realloc(alloc, size);
 
 #   if RUSTRT_TRACK_ALLOCATIONS >= 1
-    assert(alloc->magic == MAGIC);
+    assert(newMem->magic == MAGIC);
     newMem->size = orig_size;
 #   endif
 
@@ -141,7 +146,7 @@ memory_region::~memory_region() {
                 alloc_header *header = (alloc_header*)_allocation_list[i];
                 printf("allocation (%s) 0x%" PRIxPTR " was not freed\n",
                        header->tag,
-                       (uintptr_t) &header->data);
+                       (uintptr_t) get_data(header));
                 ++leak_count;
             }
         }
@@ -167,7 +172,7 @@ memory_region::release_alloc(void *mem) {
     if (_synchronized) { _lock.lock(); }
     if (_allocation_list[alloc->index] != alloc) {
         printf("free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n",
-               (uintptr_t) &alloc->data, alloc->tag);
+               (uintptr_t) get_data(alloc), alloc->tag);
         _srv->fatal("not in allocation_list", __FILE__, __LINE__, "");
     }
     else {
@@ -222,6 +227,5 @@ memory_region::maybe_poison(void *mem) {
 // indent-tabs-mode: nil
 // c-basic-offset: 4
 // buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
 // End:
 //
index 75f3f9be941a3a609de40d3ebe1b4f7dd7e78d4f..4caecb3cd5df7d73faca74c797826b66802c6b48 100644 (file)
@@ -80,7 +80,6 @@ inline void *operator new(size_t size, memory_region *region,
 // indent-tabs-mode: nil
 // c-basic-offset: 4
 // buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
 // End:
 //