use _filtered routines for printing so symbolic addresses show up in the right place
[deliverable/binutils-gdb.git] / gdb / gmalloc.c
index d533eaa49602d27a58f8c3de00dc8f8a01c2afde..8cbf4beab957ba7cc484fdfb8ee67d2dfe551f5f 100755 (executable)
@@ -205,7 +205,7 @@ typedef unsigned long size_t;
 #include <stddef.h>
 #endif
 
-extern void EXFUN(abort, (void));
+extern void EXFUN(abort, (NOARGS));
 extern void EXFUN(free, (PTR));
 extern PTR EXFUN(malloc, (size_t));
 extern PTR EXFUN(realloc, (PTR, size_t));
@@ -267,9 +267,19 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
    fragments in a block have been freed, the block itself is freed.  */
 #define INT_BIT                (CHAR_BIT * sizeof(int))
 #define BLOCKLOG       (INT_BIT > 16 ? 12 : 9)
-#define BLOCKSIZE      (1 << BLOCKLOG)
+#define BLOCKSIZE      ((unsigned int) 1 << BLOCKLOG)
 #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
 
+/* The difference between two pointers is a signed int.  On machines where
+   the data addresses have the high bit set, we need to ensure that the
+   difference becomes an unsigned int when we are using the address as an
+   integral value.  In addition, when using with the '%' operator, the
+   sign of the result is machine dependent for negative values, so force
+   it to be treated as an unsigned int. */
+
+#define ADDR2UINT(addr)        ((unsigned int) ((char *) (addr) - (char *) NULL))
+#define RESIDUAL(addr) ((unsigned int) (ADDR2UINT (addr) % BLOCKSIZE))
+
 /* Determine the amount of memory spanned by the initial heap table
    (not an absolute limit).  */
 #define HEAP           (INT_BIT > 16 ? 4194304 : 65536)
@@ -367,7 +377,7 @@ extern PTR EXFUN((*__malloc_hook), (size_t __size));
 extern PTR EXFUN((*__realloc_hook), (PTR __ptr, size_t __size));
 
 /* Activate a standard collection of debugging hooks.  */
-extern void EXFUN(mcheck, (void EXFUN((*func), (void))));
+extern void EXFUN(mcheck, (void EXFUN((*func), (NOARGS))));
 
 /* Statistics available to the user.  */
 struct mstats
@@ -558,8 +568,7 @@ DEFUN(__free, (ptr), PTR ptr)
             it is the first free fragment of this block. */
          prev = (struct list *) ptr;
          _heapinfo[block].busy.info.frag.nfree = 1;
-         _heapinfo[block].busy.info.frag.first = (unsigned int)
-           (((char *) ptr - (char *) NULL) % BLOCKSIZE >> type);
+         _heapinfo[block].busy.info.frag.first = RESIDUAL (ptr) >> type;
          prev->next = _fraghead[type].next;
          prev->prev = &_fraghead[type];
          prev->prev->next = prev;
@@ -656,7 +665,7 @@ DEFUN(align, (size), size_t size)
   unsigned int adj;
 
   result = (*__morecore)(size);
-  adj = (unsigned int) ((char *) result - (char *) NULL) % BLOCKSIZE;
+  adj = RESIDUAL (result);
   if (adj != 0)
     {
       adj = BLOCKSIZE - adj;
@@ -769,8 +778,8 @@ DEFUN(malloc, (size), size_t size)
            next->next->prev = next->prev;
          block = BLOCK(result);
          if (--_heapinfo[block].busy.info.frag.nfree != 0)
-           _heapinfo[block].busy.info.frag.first = (unsigned int)
-             (((char *) next->next - (char *) NULL) % BLOCKSIZE) >> log;
+           _heapinfo[block].busy.info.frag.first =
+             RESIDUAL (next->next) >> log;
 
          /* Update the statistics.  */
          ++_chunks_used;
@@ -1145,7 +1154,7 @@ DEFUN(valloc, (size), size_t size)
   result = malloc(size + pagesize);
   if (result == NULL)
     return NULL;
-  adj = (unsigned int) ((char *) result - (char *) NULL) % pagesize;
+  adj = (unsigned int) ((unsigned int)((char *) result - (char *) NULL)) % pagesize;
   if (adj != 0)
     result = (char *) result + pagesize - adj;
   return result;
This page took 0.023918 seconds and 4 git commands to generate.