Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup heap switching code
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 10 Feb 2015 08:41:53 +0000 (09:41 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 10 Feb 2015 09:29:24 +0000 (10:29 +0100)
include/xbt/mmalloc.h
src/mc/mc_client_api.c
src/mc/mc_comm_determinism.c
src/mc/mc_global.c
src/mc/mc_ignore.c
src/mc/mc_liveness.c
src/mc/mc_process.c
src/mc/mc_safety.c
src/mc/mc_visited.c
src/xbt/mmalloc/mm_legacy.c

index 40275c8..5e32858 100644 (file)
@@ -62,7 +62,7 @@ XBT_PUBLIC( void ) *xbt_mheap_destroy(xbt_mheap_t md);
 XBT_PUBLIC( xbt_mheap_t ) mmalloc_get_default_md(void);
 
 /* To change the heap used when using the legacy version malloc/free/realloc and such */
-void mmalloc_set_current_heap(xbt_mheap_t new_heap);
+xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap);
 xbt_mheap_t mmalloc_get_current_heap(void);
 
 struct s_mc_snapshot;
index 9c7b2e7..fad7c0f 100644 (file)
@@ -68,9 +68,7 @@ void MC_ignore(void* addr, size_t size)
   }
 
   // TODO, remove this once the migration has been completed
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   MC_process_ignore_memory(&mc_model_checker->process, addr, size);
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
index c96db70..fc4e1bd 100644 (file)
@@ -262,16 +262,12 @@ void complete_comm_pattern(xbt_dynar_t list, smx_synchro_t comm)
 
 void MC_pre_modelcheck_comm_determinism(void)
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
+  MC_SET_MC_HEAP;
 
   mc_state_t initial_state = NULL;
   smx_process_t process;
   int i;
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
-
   if (_sg_mc_visited > 0)
     visited_states = xbt_dynar_new(sizeof(mc_visited_state_t), visited_state_free_voidp);
  
index 178fee1..27c83bd 100644 (file)
@@ -23,6 +23,7 @@
 
 #ifdef HAVE_MC
 #include <libunwind.h>
+#include <xbt/mmalloc.h>
 
 #include "../xbt/mmalloc/mmprivate.h"
 #include "mc_object_info.h"
@@ -114,14 +115,12 @@ void MC_init_pid(pid_t pid, int socket)
     }
   }
 
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   mc_time = xbt_new0(double, simix_process_maxpid);
 
   /* Initialize the data structures that must be persistent across every
      iteration of the model-checker (in RAW memory) */
 
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   mc_model_checker = MC_model_checker_new(pid, socket);
 
@@ -188,8 +187,7 @@ void MC_init_pid(pid_t pid, int socket)
     }
   }
 
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 
   if (mc_mode == MC_MODE_CLIENT) {
     // This will move somehwere else:
@@ -203,13 +201,9 @@ void MC_init_pid(pid_t pid, int socket)
 
 static void MC_modelcheck_comm_determinism_init(void)
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -228,21 +222,16 @@ static void MC_modelcheck_comm_determinism_init(void)
 
   MC_modelcheck_comm_determinism();
 
-  if(mc_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 static void MC_modelcheck_safety_init(void)
 {
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   _sg_mc_safety = 1;
 
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -259,8 +248,7 @@ static void MC_modelcheck_safety_init(void)
 
   MC_modelcheck_safety();
 
-  if (mc_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 
   xbt_abort();
   //MC_exit();
@@ -268,15 +256,11 @@ static void MC_modelcheck_safety_init(void)
 
 static void MC_modelcheck_liveness_init()
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   _sg_mc_liveness = 1;
 
   MC_init();
 
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   /* Create exploration stack */
   mc_stack = xbt_fifo_new();
@@ -292,8 +276,7 @@ static void MC_modelcheck_liveness_init()
   MC_print_statistics(mc_stats);
   xbt_free(mc_time);
 
-  if (mc_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 
 }
 
@@ -382,7 +365,7 @@ void mc_update_comm_pattern(mc_call_type call_type, smx_simcall_t req, int value
  */
 void MC_replay(xbt_fifo_t stack, int start)
 {
-  int raw_mem = (mmalloc_get_current_heap() == mc_heap);
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int value, i = 1, count = 1, j;
   char *req_str;
@@ -505,13 +488,7 @@ void MC_replay(xbt_fifo_t stack, int start)
   }
 
   XBT_DEBUG("**** End Replay ****");
-
-  if (raw_mem)
-    MC_SET_MC_HEAP;
-  else
-    MC_SET_STD_HEAP;
-
-
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
@@ -592,8 +569,7 @@ void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
  */
 void MC_dump_stack_safety(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   MC_show_stack_safety(stack);
 
@@ -608,20 +584,13 @@ void MC_dump_stack_safety(xbt_fifo_t stack)
 
   }
 
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-  else
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 
 void MC_show_stack_safety(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int value;
   mc_state_t state;
@@ -640,8 +609,7 @@ void MC_show_stack_safety(xbt_fifo_t stack)
     }
   }
 
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_show_deadlock(smx_simcall_t req)
@@ -686,26 +654,16 @@ void MC_show_stack_liveness(xbt_fifo_t stack)
 
 void MC_dump_stack_liveness(xbt_fifo_t stack)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   mc_pair_t pair;
-
-  MC_SET_MC_HEAP;
   while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
     MC_pair_delete(pair);
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 
 void MC_print_statistics(mc_stats_t stats)
 {
-  xbt_mheap_t previous_heap = mmalloc_get_current_heap();
-
   if (stats->expanded_pairs == 0) {
     XBT_INFO("Expanded states = %lu", stats->expanded_states);
     XBT_INFO("Visited states = %lu", stats->visited_states);
@@ -714,7 +672,7 @@ void MC_print_statistics(mc_stats_t stats)
     XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
   }
   XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0')) {
     fprintf(dot_output, "}\n");
     fclose(dot_output);
@@ -727,51 +685,34 @@ void MC_print_statistics(mc_stats_t stats)
       XBT_INFO("Send-deterministic : %s",
                !initial_global_state->send_deterministic ? "No" : "Yes");
   }
-  mmalloc_set_current_heap(previous_heap);
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_automaton_load(const char *file)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   if (_mc_property_automaton == NULL)
     _mc_property_automaton = xbt_automaton_new();
 
   xbt_automaton_load(_mc_property_automaton, file);
-
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_automaton_new_propositional_symbol(const char *id, void *fct)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   if (_mc_property_automaton == NULL)
     _mc_property_automaton = xbt_automaton_new();
 
   xbt_automaton_propositional_symbol_new(_mc_property_automaton, id, fct);
-
-  MC_SET_STD_HEAP;
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_dump_stacks(FILE* file)
 {
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int nstack = 0;
   stack_region_t current_stack;
@@ -793,9 +734,7 @@ void MC_dump_stacks(FILE* file)
 
     ++nstack;
   }
-
-  if (raw_mem_set)
-    MC_SET_MC_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 #endif
 
index d0c2c37..fde29b8 100644 (file)
@@ -125,8 +125,7 @@ void MC_heap_region_ignore_send(mc_heap_ignore_region_t region)
 // FIXME, cross-process support? (or make this it is used on the app-side)
 void MC_ignore_heap(void *address, size_t size)
 {
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   mc_heap_ignore_region_t region = xbt_new0(s_mc_heap_ignore_region_t, 1);
   region->address = address;
@@ -152,9 +151,7 @@ void MC_ignore_heap(void *address, size_t size)
   if (mc_mode == MC_MODE_CLIENT)
     MC_heap_region_ignore_send(region);
 #endif
-
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_remove_ignore_heap(void *address, size_t size)
@@ -167,9 +164,7 @@ void MC_remove_ignore_heap(void *address, size_t size)
     MC_client_send_message(&message, sizeof(message));
   }
 
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   unsigned int cursor = 0;
   int start = 0;
@@ -202,20 +197,14 @@ void MC_remove_ignore_heap(void *address, size_t size)
     xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
     MC_remove_ignore_heap(address, size);
   }
-
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 // FIXME, cross-process support?
 void MC_ignore_global_variable(const char *name)
 {
   mc_process_t process = &mc_model_checker->process;
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
-
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
   xbt_assert(process->object_infos, "MC subsystem not initialized");
 
   size_t n = process->object_infos_size;
@@ -241,9 +230,7 @@ void MC_ignore_global_variable(const char *name)
       }
     }
   }
-
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 /** \brief Ignore a local variable in a scope
@@ -326,14 +313,9 @@ static void MC_ignore_local_variable_in_object(const char *var_name,
 void MC_ignore_local_variable(const char *var_name, const char *frame_name)
 {
   mc_process_t process = &mc_model_checker->process;
-
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   if (strcmp(frame_name, "*") == 0)
     frame_name = NULL;
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   size_t n = process->object_infos_size;
   size_t i;
@@ -341,9 +323,7 @@ void MC_ignore_local_variable(const char *var_name, const char *frame_name)
     MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]);
   }
 
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_stack_area_add(stack_region_t stack_area)
@@ -366,9 +346,7 @@ void MC_stack_area_add(stack_region_t stack_area)
  */
 void MC_new_stack_area(void *stack, smx_process_t process, void *context, size_t size)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   stack_region_t region = xbt_new0(s_stack_region_t, 1);
   region->address = stack;
@@ -393,8 +371,7 @@ void MC_new_stack_area(void *stack, smx_process_t process, void *context, size_t
 
   MC_stack_area_add(region);
 
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 void MC_process_ignore_memory(mc_process_t process, void *addr, size_t size)
index f927f2f..3799185 100644 (file)
@@ -50,10 +50,7 @@ static mc_visited_pair_t is_reached_acceptance_pair(int pair_num,
                                                     xbt_dynar_t
                                                     atomic_propositions)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   mc_visited_pair_t pair = NULL;
   pair = MC_visited_pair_new(pair_num, automaton_state, atomic_propositions);
@@ -101,10 +98,7 @@ static mc_visited_pair_t is_reached_acceptance_pair(int pair_num,
                 fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n",
                         initial_global_state->prev_pair, pair_test->num,
                         initial_global_state->prev_req);
-
-              if (!raw_mem_set)
-                MC_SET_STD_HEAP;
-
+              mmalloc_set_current_heap(heap);
               return NULL;
             }
           }
@@ -127,20 +121,13 @@ static mc_visited_pair_t is_reached_acceptance_pair(int pair_num,
     }
 
   }
-
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
   return pair;
-
 }
 
 static void remove_acceptance_pair(int pair_num)
 {
-
-  int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   unsigned int cursor = 0;
   mc_visited_pair_t pair_test = NULL;
@@ -161,8 +148,7 @@ static void remove_acceptance_pair(int pair_num)
     MC_visited_pair_delete(pair_test);
   }
 
-  if (!raw_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 
@@ -275,14 +261,11 @@ void MC_pre_modelcheck_liveness(void)
     MC_SET_MC_HEAP;
   else
     MC_SET_STD_HEAP;
-
-
 }
 
 
 void MC_modelcheck_liveness()
 {
-
   smx_process_t process;
   mc_pair_t current_pair = NULL;
 
index 2ed9f26..65c77a8 100644 (file)
@@ -141,8 +141,7 @@ void MC_process_refresh_heap(mc_process_t process)
   assert(!MC_process_is_self(process));
   // Read/dereference/refresh the std_heap pointer:
   if (!process->heap) {
-    xbt_mheap_t oldheap  = mmalloc_get_current_heap();
-    MC_SET_MC_HEAP;
+    xbt_mheap_t oldheap  = mmalloc_set_current_heap(mc_heap);
     process->heap = malloc(sizeof(struct mdesc));
     mmalloc_set_current_heap(oldheap);
   }
@@ -160,11 +159,10 @@ void MC_process_refresh_malloc_info(mc_process_t process)
   // Refresh process->heapinfo:
   size_t malloc_info_bytesize = process->heap->heaplimit * sizeof(malloc_info);
 
-  xbt_mheap_t oldheap  = mmalloc_get_current_heap();
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap  = mmalloc_set_current_heap(mc_heap);
   process->heap_info = (malloc_info*) realloc(process->heap_info,
     malloc_info_bytesize);
-  mmalloc_set_current_heap(oldheap);
+  mmalloc_set_current_heap(heap);
 
   MC_process_read(process, MC_ADDRESS_SPACE_READ_FLAGS_NONE,
     process->heap_info,
index 658c185..3898df5 100644 (file)
@@ -22,15 +22,10 @@ xbt_dict_t first_enabled_state;
  */
 void MC_pre_modelcheck_safety()
 {
-
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
   mc_state_t initial_state = NULL;
   smx_process_t process;
 
-  /* Create the initial state and push it into the exploration stack */
-  if (!mc_mem_set)
-    MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   if (_sg_mc_visited > 0)
     visited_states =
@@ -76,9 +71,7 @@ void MC_pre_modelcheck_safety()
       }
     }
   }
-
-  if (!mc_mem_set)
-    MC_SET_STD_HEAP;
+  mmalloc_set_current_heap(heap);
 }
 
 
index 95fcc37..8010fde 100644 (file)
@@ -106,9 +106,7 @@ void MC_visited_pair_delete(mc_visited_pair_t p)
 int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max)
 {
 
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   int cursor = 0, previous_cursor, next_cursor;
   int nb_processes, heap_bytes_used, nb_processes_test, heap_bytes_used_test;
@@ -196,16 +194,13 @@ int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max)
           *max = next_cursor;
           next_cursor++;
         }
-        if (!mc_mem_set)
-          MC_SET_STD_HEAP;
+        mmalloc_set_current_heap(heap);
         return -1;
       }
     }
   }
 
-  if (!mc_mem_set)
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
   return cursor;
 }
 
@@ -232,19 +227,14 @@ mc_visited_state_t is_visited_state()
     }
   }
 
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   mc_visited_state_t new_state = visited_state_new();
 
   if (xbt_dynar_is_empty(visited_states)) {
 
     xbt_dynar_push(visited_states, &new_state);
-
-    if (!mc_mem_set)
-      MC_SET_STD_HEAP;
-
+    mmalloc_set_current_heap(heap);
     return NULL;
 
   } else {
@@ -303,8 +293,7 @@ mc_visited_state_t is_visited_state()
           xbt_dynar_remove_at(visited_states, cursor, NULL);
           xbt_dynar_insert_at(visited_states, cursor, &new_state);
 
-          if (!mc_mem_set)
-            MC_SET_STD_HEAP;
+          mmalloc_set_current_heap(heap);
           return state_test;
         }
         cursor++;
@@ -348,11 +337,8 @@ mc_visited_state_t is_visited_state()
       xbt_dynar_remove_at(visited_states, index2, NULL);
     }
 
-    if (!mc_mem_set)
-      MC_SET_STD_HEAP;
-
+    mmalloc_set_current_heap(heap);
     return NULL;
-
   }
 }
 
@@ -367,9 +353,7 @@ int is_visited_pair(mc_visited_pair_t pair, int pair_num,
   if (_sg_mc_visited == 0)
     return -1;
 
-  int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
-  MC_SET_MC_HEAP;
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
 
   mc_visited_pair_t new_pair = NULL;
 
@@ -452,8 +436,7 @@ int is_visited_pair(mc_visited_pair_t pair, int pair_num,
               } else {
                 MC_visited_pair_delete(pair_test);
               }
-              if (!mc_mem_set)
-                MC_SET_STD_HEAP;
+              mmalloc_set_current_heap(heap);
               return new_pair->other_num;
             }
           }
@@ -497,8 +480,6 @@ int is_visited_pair(mc_visited_pair_t pair, int pair_num,
 
   }
 
-  if (!mc_mem_set)
-    MC_SET_STD_HEAP;
-
+  mmalloc_set_current_heap(heap);
   return -1;
 }
index 3f91455..fac98b1 100644 (file)
@@ -40,9 +40,11 @@ xbt_mheap_t mmalloc_get_current_heap(void)
   return __mmalloc_current_heap;
 }
 
-void mmalloc_set_current_heap(xbt_mheap_t new_heap)
+xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap)
 {
+  xbt_mheap_t heap = __mmalloc_current_heap;
   __mmalloc_current_heap = new_heap;
+  return heap;
 }
 
 #ifdef MMALLOC_WANT_OVERRIDE_LEGACY