This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: malloc.c cleanups


These are preparatory cleanups for BP support.
No build regressions.  No binary changes.

OK?

2000-07-18  Greg McGary  <greg@mcgary.org>

	* malloc/malloc.c (next_chunk, prev_chunk, inuse_bit_at_offset,
	set_inuse_bit_at_offset, clear_inuse_bit_at_offset, set_foot):
	Define in terms of chunk_at_offset.
	(inuse, set_inuse, clear_inuse): Define in terms of next_chunk.
	(next_bin, prev_bin): offset by size of real array elements.
	(chunk_align): Make `m' a scalar, since that's how it's used.

Index: malloc/malloc.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/malloc.c,v
retrieving revision 1.64
diff -u -p -r1.64 malloc.c
--- malloc.c	2000/07/17 21:37:47	1.64
+++ malloc.c	2000/07/18 07:17:01
@@ -1330,11 +1330,11 @@ static void      free_atfork();
 
 /* Ptr to next physical malloc_chunk. */
 
-#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->size & ~PREV_INUSE) ))
+#define next_chunk(p) chunk_at_offset((p), (p)->size & ~PREV_INUSE)
 
 /* Ptr to previous physical malloc_chunk */
 
-#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_size) ))
+#define prev_chunk(p) chunk_at_offset((p), -(p)->prev_size)
 
 
 /* Treat space at ptr + offset as a chunk */
@@ -1350,8 +1350,7 @@ static void      free_atfork();
 
 /* extract p's inuse bit */
 
-#define inuse(p) \
- ((((mchunkptr)(((char*)(p))+((p)->size & ~PREV_INUSE)))->size) & PREV_INUSE)
+#define inuse(p) (next_chunk(p)->size & PREV_INUSE)
 
 /* extract inuse bit of previous chunk */
 
@@ -1363,22 +1362,20 @@ static void      free_atfork();
 
 /* set/clear chunk as in use without otherwise disturbing */
 
-#define set_inuse(p) \
- ((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size |= PREV_INUSE
+#define set_inuse(p) (next_chunk(p)->size |= PREV_INUSE)
 
-#define clear_inuse(p) \
- ((mchunkptr)(((char*)(p)) + ((p)->size & ~PREV_INUSE)))->size &= ~(PREV_INUSE)
+#define clear_inuse(p) (next_chunk(p)->size &= ~PREV_INUSE)
 
 /* check/set/clear inuse bits in known places */
 
-#define inuse_bit_at_offset(p, s)\
- (((mchunkptr)(((char*)(p)) + (s)))->size & PREV_INUSE)
+#define inuse_bit_at_offset(p, s) \
+  (chunk_at_offset((p), (s))->size & PREV_INUSE)
 
-#define set_inuse_bit_at_offset(p, s)\
- (((mchunkptr)(((char*)(p)) + (s)))->size |= PREV_INUSE)
+#define set_inuse_bit_at_offset(p, s) \
+  (chunk_at_offset((p), (s))->size |= PREV_INUSE)
 
-#define clear_inuse_bit_at_offset(p, s)\
- (((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE))
+#define clear_inuse_bit_at_offset(p, s) \
+  (chunk_at_offset((p), (s))->size &= ~(PREV_INUSE))
 
 
 
@@ -1401,7 +1398,7 @@ static void      free_atfork();
 
 /* Set size at footer (only when chunk is not in use) */
 
-#define set_foot(p, s)   (((mchunkptr)((char*)(p) + (s)))->prev_size = (s))
+#define set_foot(p, s)   (chunk_at_offset(p, s)->prev_size = (s))
 
 
 
@@ -1411,8 +1408,8 @@ static void      free_atfork();
 
 #define bin_at(a, i)   ((mbinptr)((char*)&(((a)->av)[2*(i) + 2]) - 2*SIZE_SZ))
 #define init_bin(a, i) ((a)->av[2*i+2] = (a)->av[2*i+3] = bin_at((a), i))
-#define next_bin(b)    ((mbinptr)((char*)(b) + 2 * sizeof(mbinptr)))
-#define prev_bin(b)    ((mbinptr)((char*)(b) - 2 * sizeof(mbinptr)))
+#define next_bin(b)    ((mbinptr)((char*)(b) + 2 * sizeof(((arena*)0)->av[0])))
+#define prev_bin(b)    ((mbinptr)((char*)(b) - 2 * sizeof(((arena*)0)->av[0])))
 
 /*
    The first 2 bins are never indexed. The corresponding av cells are instead
@@ -3532,7 +3529,7 @@ chunk_align(ar_ptr, nb, alignment)
 arena* ar_ptr; INTERNAL_SIZE_T nb; size_t alignment;
 #endif
 {
-  char*     m;                /* memory returned by malloc call */
+  unsigned long m;            /* memory returned by malloc call */
   mchunkptr p;                /* corresponding chunk */
   char*     brk;              /* alignment point within p */
   mchunkptr newp;             /* chunk to return */
@@ -3546,9 +3543,9 @@ arena* ar_ptr; INTERNAL_SIZE_T nb; size_
   if (p == 0)
     return 0; /* propagate failure */
 
-  m = (char*)chunk2mem(p);
+  m = (unsigned long)chunk2mem(p);
 
-  if ((((unsigned long)(m)) % alignment) == 0) /* aligned */
+  if ((m % alignment) == 0) /* aligned */
   {
 #if HAVE_MMAP
     if(chunk_is_mmapped(p)) {
@@ -3567,8 +3564,7 @@ arena* ar_ptr; INTERNAL_SIZE_T nb; size_
       this is always possible.
     */
 
-    brk = (char*)mem2chunk(((unsigned long)(m + alignment - 1)) &
-                           -(long)alignment);
+    brk = (char*)mem2chunk(((m + alignment - 1)) & -(long)alignment);
     if ((long)(brk - (char*)(p)) < (long)MINSIZE) brk += alignment;
 
     newp = (mchunkptr)brk;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]