Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use xbt_malloc() and friends.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 21 Mar 2019 20:58:38 +0000 (21:58 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 21 Mar 2019 21:29:45 +0000 (22:29 +0100)
src/s4u/s4u_Host.cpp
src/s4u/s4u_Link.cpp
src/smpi/plugins/ampi/ampi.cpp

index 318727b..f8c8190 100644 (file)
@@ -338,7 +338,7 @@ sg_host_t* sg_host_list()
   xbt_assert(sg_host_count() > 0, "There is no host!");
   std::vector<simgrid::s4u::Host*> hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
 
-  sg_host_t* res = (sg_host_t*)malloc(sizeof(sg_host_t) * hosts.size());
+  sg_host_t* res = xbt_new(sg_host_t, hosts.size());
   memcpy(res, hosts.data(), sizeof(sg_host_t) * hosts.size());
 
   return res;
index 92bd54b..456c57d 100644 (file)
@@ -156,7 +156,7 @@ sg_link_t* sg_link_list()
 {
   std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
 
-  sg_link_t* res = (sg_link_t*)malloc(sizeof(sg_link_t) * links.size());
+  sg_link_t* res = xbt_new(sg_link_t, links.size());
   memcpy(res, links.data(), sizeof(sg_link_t) * links.size());
 
   return res;
index 6c005be..e0e44e0 100644 (file)
@@ -5,11 +5,12 @@
 
 #include <simgrid/plugins/load_balancer.h>
 #include <simgrid/s4u/Actor.hpp>
-#include <src/smpi/include/smpi_comm.hpp>
+#include <src/instr/instr_smpi.hpp>
 #include <src/smpi/include/smpi_actor.hpp>
+#include <src/smpi/include/smpi_comm.hpp>
 #include <src/smpi/plugins/ampi/instr_ampi.hpp>
-#include <src/instr/instr_smpi.hpp>
 #include <xbt/replay.hpp>
+#include <xbt/sysdep.h>
 
 #include "ampi.hpp"
 #include <smpi/sampi.h>
@@ -24,7 +25,7 @@ extern "C" XBT_PUBLIC void* _sampi_calloc(size_t num_elm, size_t elem_size);
 extern "C" XBT_PUBLIC void* _sampi_realloc(void* ptr, size_t size);
 extern "C" void* _sampi_malloc(size_t size)
 {
-  void* result = malloc (size); // We need the space here to prevent recursive substitution
+  void* result = xbt_malloc(size);
   alloc_table.insert({result, size});
   if (not simgrid::s4u::this_actor::is_maestro()) {
     memory_size[simgrid::s4u::this_actor::get_pid()] += size;
@@ -37,12 +38,12 @@ extern "C" void _sampi_free(void* ptr)
   size_t alloc_size = alloc_table.at(ptr);
   int my_proc_id    = simgrid::s4u::this_actor::get_pid();
   memory_size[my_proc_id] -= alloc_size;
-  free(ptr);
+  xbt_free(ptr);
 }
 
 extern "C" void* _sampi_calloc(size_t num_elm, size_t elem_size)
 {
-  void* result = calloc (num_elm, elem_size); // We need the space here to prevent recursive substitution
+  void* result = xbt_malloc0(num_elm * elem_size);
   alloc_table.insert({result, num_elm * elem_size});
   if (not simgrid::s4u::this_actor::is_maestro()) {
     memory_size[simgrid::s4u::this_actor::get_pid()] += num_elm * elem_size;
@@ -51,7 +52,7 @@ extern "C" void* _sampi_calloc(size_t num_elm, size_t elem_size)
 }
 extern "C" void* _sampi_realloc(void* ptr, size_t size)
 {
-  void* result = realloc (ptr, size); // We need the space here to prevent recursive substitution
+  void* result = xbt_realloc(ptr, size);
   int old_size = alloc_table.at(ptr);
   alloc_table.erase(ptr);
   alloc_table.insert({result, size});