Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright headers.
[simgrid.git] / src / xbt / mmalloc / mrealloc.c
index d073960..df50495 100644 (file)
@@ -1,6 +1,6 @@
 /* Change the size of a block allocated by `mmalloc'. */
 
-/* Copyright (c) 2010-2014. The SimGrid Team.
+/* Copyright (c) 2010-2018. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
 #include "mmprivate.h"
 
-/* Resize the given region to the new size, returning a pointer
-   to the (possibly moved) region.  This is optimized for speed;
-   some benchmarks seem to indicate that greater compactness is
-   achieved by unconditionally allocating and copying to a
-   new region.  This module has incestuous knowledge of the
-   internals of both mfree and mmalloc. */
+/* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for
+ * speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and
+ * copying to a new region.  This module has incestuous knowledge of the internals of both mfree and mmalloc. */
 
 void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
 {
   void *result;
-  int type;
-  size_t block, blocks, oldlimit;
+  size_t blocks;
 
   /* Only keep real realloc, and reroute hidden malloc and free to the relevant functions */
   if (size == 0) {
@@ -38,11 +34,9 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
   //printf("(%s)realloc %p to %d...",xbt_thread_self_name(),ptr,(int)size);
 
   if ((char *) ptr < (char *) mdp->heapbase || BLOCK(ptr) > mdp->heapsize) {
-    printf
-      ("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc it instead of reallocing it, see source code)\n");
-    result = mmalloc(mdp, size);
+    printf("FIXME. Ouch, this pointer is not mine, refusing to proceed (another solution would be to malloc "
+           "it instead of reallocing it, see source code)\n");
     abort();
-    return result;
   }
 
   size_t requested_size = size; // The amount of memory requested by user, for real
@@ -54,9 +48,9 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
   if (size < SMALLEST_POSSIBLE_MALLOC)
     size = SMALLEST_POSSIBLE_MALLOC;
 
-  block = BLOCK(ptr);
+  size_t block = BLOCK(ptr);
 
-  type = mdp->heapinfo[block].type;
+  int type = mdp->heapinfo[block].type;
 
   switch (type) {
   case MMALLOC_TYPE_HEAPINFO:
@@ -95,8 +89,7 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
         mdp->heapinfo[it].busy_block.busy_size = 0;
       }
 
-      mdp->heapinfo[block + blocks].busy_block.size
-        = mdp->heapinfo[block].busy_block.size - blocks;
+      mdp->heapinfo[block + blocks].busy_block.size = mdp->heapinfo[block].busy_block.size - blocks;
       mfree(mdp, ADDRESS(block + blocks));
 
       mdp->heapinfo[block].busy_block.size = blocks;
@@ -118,7 +111,7 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
            action for obvious reasons. */
       blocks = mdp->heapinfo[block].busy_block.size;
       /* Prevent free from actually returning memory to the system.  */
-      oldlimit = mdp->heaplimit;
+      size_t oldlimit = mdp->heaplimit;
       mdp->heaplimit = 0;
       mfree(mdp, ptr);
       mdp->heaplimit = oldlimit;