Use macros to hide some of the ugly casting required in the previously
authorFred Fish <fnf@specifix.com>
Sun, 8 Dec 1991 02:17:29 +0000 (02:17 +0000)
committerFred Fish <fnf@specifix.com>
Sun, 8 Dec 1991 02:17:29 +0000 (02:17 +0000)
applied fix for pointers with the high bit set.

gdb/ChangeLog
gdb/gmalloc.c

index 9021ee38fdc1f70f43aa39980c375055ca70afd4..d440f1e1ea2a3ea73c88e12dea6d39b9032316a0 100644 (file)
@@ -1,3 +1,8 @@
+Sat Dec  7 18:13:11 1991  Fred Fish  (fnf at cygnus.com)
+
+       * gmalloc.c:  Use macros to hide some of the ugly casting required
+       in the previously applied fix for pointers with high bits set.
+
 Sat Dec  7 16:49:35 1991  John Gilmore  (gnu at cygnus.com)
 
        * Makefile.in:  Roll VERSION to 4.3.1.
index cfd657959702a72f6170bc4016070cda04882588..2c26699f02f71c1755325437f165e56420f18f63 100755 (executable)
@@ -270,6 +270,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define BLOCKSIZE      (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)
@@ -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)
-           (((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) ((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)
-             (((unsigned int)((char *) next->next - (char *) NULL)) % BLOCKSIZE) >> log;
+           _heapinfo[block].busy.info.frag.first =
+             RESIDUAL (next->next) >> log;
 
          /* Update the statistics.  */
          ++_chunks_used;
This page took 0.02843 seconds and 4 git commands to generate.