Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function: xbt_dynar_sort_strings(), when the content is char*
[simgrid.git] / src / xbt / mmalloc / mm_legacy.c
index cb12f56..e9e250f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2014. The SimGrid Team.
+/* Copyright (c) 2010-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
 #include <dlfcn.h>
 
-#include "../../mc/mc_base.h"
+#include "src/mc/mc_base.h"
 #include "mmprivate.h"
-#include "xbt_modinter.h"
-#include "internal_config.h"
+#include "src/xbt_modinter.h"
+#include "src/internal_config.h"
 #include <math.h>
-#include "../mc/mc_protocol.h"
+#include "src/mc/mc_protocol.h"
 
 /* ***** Whether to use `mmalloc` of the undrlying malloc ***** */
 
@@ -67,15 +67,17 @@ static uint64_t buffer[BUFFER_SIZE];
  */
 static void* mm_fake_malloc(size_t n)
 {
+  // How many uint64_t do w need?
   size_t count = n / sizeof(uint64_t);
-  if (n && 0xff)
-    count ++;
-  if (fake_alloc_index + count < BUFFER_SIZE) {
-    uint64_t* res = buffer + fake_alloc_index;
-    fake_alloc_index += count;
-    return res;
-  }
-  exit(127);
+  if (n % sizeof(uint64_t))
+    count++;
+  // Check that we have enough availabel memory:
+  if (fake_alloc_index + count >= BUFFER_SIZE)
+    exit(127);
+  // Allocate it:
+  uint64_t* res = buffer + fake_alloc_index;
+  fake_alloc_index += count;
+  return res;
 }
 
 static void* mm_fake_calloc(size_t nmemb, size_t size)