Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib Back out the previous 2 revs. The delint'in...



details:   https://anonhg.NetBSD.org/src/rev/8b36ec8a42f6
branches:  trunk
changeset: 481486:8b36ec8a42f6
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 31 22:56:14 2000 +0000

description:
Back out the previous 2 revs.  The delint'ing of this file caused
something to break horribly on the Alpha.

diffstat:

 lib/libc/stdlib/malloc.c |  79 ++++++++++++++++++++++++-----------------------
 1 files changed, 40 insertions(+), 39 deletions(-)

diffs (273 lines):

diff -r 5e5d00b5fc27 -r 8b36ec8a42f6 lib/libc/stdlib/malloc.c
--- a/lib/libc/stdlib/malloc.c  Mon Jan 31 22:51:53 2000 +0000
+++ b/lib/libc/stdlib/malloc.c  Mon Jan 31 22:56:14 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: malloc.c,v 1.28 2000/01/23 00:49:41 mycroft Exp $      */
+/*     $NetBSD: malloc.c,v 1.29 2000/01/31 22:56:14 thorpej Exp $      */
 
 /*
  * ----------------------------------------------------------------------------
@@ -152,7 +152,7 @@
 #endif
 
 #define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask)))
-#define ptr2idx(foo) (((size_t)(foo) >> malloc_pageshift)-malloc_origo)
+#define ptr2idx(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo)
 
 #ifndef THREAD_LOCK
 #define THREAD_LOCK()
@@ -184,10 +184,10 @@
 static unsigned malloc_cache = 16;
 
 /* The offset from pagenumber to index into the page directory */
-static size_t malloc_origo;
+static u_long malloc_origo;
 
 /* The last index in the page directory we care about */
-static size_t last_idx;
+static u_long last_idx;
 
 /* Pointer to page directory. Allocated "as if with" malloc */
 static struct  pginfo **page_dir;
@@ -253,12 +253,12 @@
 /* Macro for mmap */
 #define MMAP(size) \
        mmap(0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \
-           MMAP_FD, (off_t)0);
+           MMAP_FD, 0);
 
 /*
  * Necessary function declarations
  */
-static int extend_pgdir(size_t idx);
+static int extend_pgdir(u_long idx);
 static void *imalloc(size_t size);
 static void ifree(void *ptr);
 static void *irealloc(void *ptr, size_t size);
@@ -294,11 +294,11 @@
  * Allocate a number of pages from the OS
  */
 static void *
-map_pages(size_t pages)
+map_pages(int pages)
 {
     caddr_t result, tail;
 
-    result = (caddr_t)pageround((size_t)sbrk(0));
+    result = (caddr_t)pageround((u_long)sbrk(0));
     tail = result + (pages << malloc_pageshift);
 
     if (brk(tail)) {
@@ -321,13 +321,15 @@
  * Extend page directory
  */
 static int
-extend_pgdir(size_t idx)
+extend_pgdir(u_long idx)
 {
     struct  pginfo **new, **old;
-    size_t newlen, oldlen;
+    int i, oldlen;
 
     /* Make it this many pages */
-    newlen = pageround(idx * sizeof *page_dir) + malloc_pagesize;
+    i = idx * sizeof *page_dir;
+    i /= malloc_pagesize;
+    i += 2;
 
     /* remember the old mapping size */
     oldlen = malloc_ninfo * sizeof *page_dir;
@@ -348,15 +350,16 @@
      */
 
     /* Get new pages */
-    new = (struct pginfo**) MMAP(newlen);
+    new = (struct pginfo**) MMAP(i * malloc_pagesize);
     if (new == (struct pginfo **)-1)
        return 0;
 
     /* Copy the old stuff */
-    memcpy(new, page_dir, oldlen);
+    memcpy(new, page_dir,
+           malloc_ninfo * sizeof *page_dir);
 
     /* register the new size */
-    malloc_ninfo = newlen / sizeof *page_dir;
+    malloc_ninfo = i * malloc_pagesize / sizeof *page_dir;
 
     /* swap the pointers */
     old = page_dir;
@@ -380,7 +383,7 @@
     /*
      * Compute page-size related variables.
      */
-    malloc_pagesize = (size_t)sysconf(_SC_PAGESIZE);
+    malloc_pagesize = sysconf(_SC_PAGESIZE);
     malloc_pagemask = malloc_pagesize - 1;
     for (malloc_pageshift = 0;
         (1UL << malloc_pageshift) != malloc_pagesize;
@@ -465,7 +468,7 @@
      * We need a maximum of malloc_pageshift buckets, steal these from the
      * front of the page_directory;
      */
-    malloc_origo = pageround((size_t)sbrk(0)) >> malloc_pageshift;
+    malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift;
     malloc_origo -= malloc_pageshift;
 
     malloc_ninfo = malloc_pagesize / sizeof *page_dir;
@@ -496,7 +499,7 @@
     void *p, *delay_free = 0;
     int i;
     struct pgfree *pf;
-    size_t idx;
+    u_long idx;
 
     size = pageround(size);
 
@@ -581,8 +584,7 @@
 {
     struct  pginfo *bp;
     void *pp;
-    int i, k;
-    size_t l;
+    int i, k, l;
 
     /* Allocate a new bucket */
     pp = malloc_pages(malloc_pagesize);
@@ -616,7 +618,7 @@
 
     /* Do a bunch at a time */
     for(;k-i >= MALLOC_BITS; i += MALLOC_BITS)
-       bp->bits[i / MALLOC_BITS] = ~0U;
+       bp->bits[i / MALLOC_BITS] = ~0;
 
     for(; i < k; i++)
         bp->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
@@ -649,8 +651,7 @@
 static void *
 malloc_bytes(size_t size)
 {
-    size_t i;
-    int j;
+    int i,j;
     u_int u;
     struct  pginfo *bp;
     int k;
@@ -696,7 +697,7 @@
     k <<= bp->shift;
 
     if (malloc_junk)
-       memset((u_char*)bp->page + k, SOME_JUNK, (size_t)bp->size);
+       memset((u_char*)bp->page + k, SOME_JUNK, bp->size);
 
     return (u_char *)bp->page + k;
 }
@@ -735,9 +736,9 @@
 irealloc(void *ptr, size_t size)
 {
     void *p;
-    size_t osize, idx;
+    u_long osize, idx;
     struct pginfo **mp;
-    size_t i;
+    int i;
 
     if (suicide)
        abort();
@@ -759,7 +760,7 @@
     if (*mp == MALLOC_FIRST) {                 /* Page allocation */
 
        /* Check the pointer */
-       if ((size_t)ptr & malloc_pagemask) {
+       if ((u_long)ptr & malloc_pagemask) {
            wrtwarning("modified (page-) pointer.\n");
            return 0;
        }
@@ -777,13 +778,13 @@
     } else if (*mp >= MALLOC_MAGIC) {          /* Chunk allocation */
 
        /* Check the pointer for sane values */
-       if (((size_t)ptr & ((*mp)->size-1))) {
+       if (((u_long)ptr & ((*mp)->size-1))) {
            wrtwarning("modified (chunk-) pointer.\n");
            return 0;
        }
 
        /* Find the chunk index in the page */
-       i = ((size_t)ptr & malloc_pagemask) >> (*mp)->shift;
+       i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift;
 
        /* Verify that it isn't a free chunk already */
         if ((*mp)->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) {
@@ -825,11 +826,11 @@
  */
 
 static __inline__ void
-free_pages(void *ptr, size_t idx, struct pginfo *info)
+free_pages(void *ptr, int idx, struct pginfo *info)
 {
-    size_t i;
+    int i;
     struct pgfree *pf, *pt=0;
-    size_t l;
+    u_long l;
     void *tail;
 
     if (info == MALLOC_FREE) {
@@ -842,7 +843,7 @@
        return;
     }
 
-    if ((size_t)ptr & malloc_pagemask) {
+    if ((u_long)ptr & malloc_pagemask) {
        wrtwarning("modified (page-) pointer.\n");
        return;
     }
@@ -955,16 +956,16 @@
  */
 
 static __inline__ void
-free_bytes(void *ptr, size_t idx, struct pginfo *info)
+free_bytes(void *ptr, int idx, struct pginfo *info)
 {
-    size_t i;
+    int i;
     struct pginfo **mp;
     void *vp;
 
     /* Find the chunk number on the page */
-    i = ((size_t)ptr & malloc_pagemask) >> info->shift;
+    i = ((u_long)ptr & malloc_pagemask) >> info->shift;
 
-    if (((size_t)ptr & (info->size-1))) {
+    if (((u_long)ptr & (info->size-1))) {
        wrtwarning("modified (chunk-) pointer.\n");
        return;
     }
@@ -975,7 +976,7 @@
     }
 
     if (malloc_junk)
-       memset(ptr, SOME_JUNK, (size_t)info->size);
+       memset(ptr, SOME_JUNK, info->size);
 
     info->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
     info->free++;
@@ -1009,7 +1010,7 @@
     *mp = info->next;
 
     /* Free the page & the info structure if need be */
-    page_dir[idx] = MALLOC_FIRST;
+    page_dir[ptr2idx(info->page)] = MALLOC_FIRST;
     vp = info->page;           /* Order is important ! */
     if(vp != (void*)info) 
        ifree(info);
@@ -1020,7 +1021,7 @@
 ifree(void *ptr)
 {
     struct pginfo *info;
-    size_t idx;
+    int idx;
 
     /* This is legal */
     if (!ptr)



Home | Main Index | Thread Index | Old Index