Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further little clarifications in mmalloc comments
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 2 Feb 2012 15:20:32 +0000 (16:20 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 2 Feb 2012 15:20:32 +0000 (16:20 +0100)
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmemalign.c
src/xbt/mmalloc/mmorecore.c

index 23db293..82876e5 100644 (file)
@@ -32,7 +32,8 @@ static void *align(struct mdesc *mdp, size_t size)
    * complete the reservation by also asking for the full lastest block.
    *
    * Also, the returned block is aligned to the end of block (but I've
-   * no fucking idea of why, actually -- http://abstrusegoose.com/432).
+   * no fucking idea of why, actually -- http://abstrusegoose.com/432 --
+   * but not doing so seems to lead to issues).
    */
   adj = RESIDUAL(result, BLOCKSIZE);
   if (adj != 0) {
index cf0cef7..3b600be 100644 (file)
@@ -24,9 +24,9 @@ void *mmemalign(xbt_mheap_t mdp, size_t alignment, size_t size)
           break;
         }
       }
-      if (l == NULL) {
+      if (l == NULL) { /* No empty entry. Create & link a new one */
         l = (struct alignlist *) mmalloc(mdp, sizeof(struct alignlist));
-        if (l == NULL) {
+        if (l == NULL) {  /* malloc error */
           mfree(mdp, result);
           return (NULL);
         }
index 9d78336..9f31583 100644 (file)
@@ -113,17 +113,15 @@ void *mmorecore(struct mdesc *mdp, int size)
                    MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) |
                    MAP_FIXED, MAP_ANON_OR_FD(mdp), foffset);
 
-      if (mapto != (void *) -1/* That's MAP_FAILED */) {
+      if (mapto == (void *) -1/* That's MAP_FAILED */)
+         THROWF(system_error,0,"mmap returned MAP_FAILED! error: %s",strerror(errno));
 
-        if (mdp->top == 0)
-          mdp->base = mdp->breakval = mapto;
+      if (mdp->top == 0)
+         mdp->base = mdp->breakval = mapto;
 
-        mdp->top = PAGE_ALIGN((char *) mdp->breakval + size);
-        result = (void *) mdp->breakval;
-        mdp->breakval = (char *) mdp->breakval + size;
-      } else {
-       THROWF(system_error,0,"mmap returned MAP_FAILED! error: %s",strerror(errno));
-      }
+      mdp->top = PAGE_ALIGN((char *) mdp->breakval + size);
+      result = (void *) mdp->breakval;
+      mdp->breakval = (char *) mdp->breakval + size;
     } else {
       result = (void *) mdp->breakval;
       mdp->breakval = (char *) mdp->breakval + size;