ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/malloc.c
(Generate patch)

Comparing ray/src/common/malloc.c (file contents):
Revision 1.15 by greg, Mon Aug 26 10:49:08 1991 UTC vs.
Revision 2.3 by greg, Fri Feb 7 15:10:32 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 43 | Line 43 | static unsigned        m_nwasted = 0;
43   #endif
44   #define  BYTES_WORD     sizeof(ALIGN)
45  
46 + #ifndef  MAXINCR
47   #define  MAXINCR        (1<<16)                 /* largest sbrk(2) increment */
47
48 #ifdef  NOVMEM
49 #define  getpagesize()  1024
48   #endif
49                                          /* malloc free lists */
50   typedef union m_head {
# Line 235 | Line 233 | register unsigned  n;
233                  pagesz = amnt = getpagesize();
234                  nrem = (int)sbrk(0);                    /* page align break */
235                  nrem = pagesz - (nrem&(pagesz-1));
236 <                bpos = sbrk(nrem);                      /* word aligned! */
236 >                bpos = sbrk(nrem);
237                  if ((int)bpos == -1)
238                          return(NULL);
239   #ifdef MSTATS
240                  b_nsbrked += nrem;
241   #endif
242 +                thisamnt = BYTES_WORD - ((unsigned)bpos&(BYTES_WORD-1));
243 +                if (thisamnt < BYTES_WORD) {            /* align pointer */
244 +                        bpos += thisamnt;
245 +                        nrem -= thisamnt;
246 +                }
247          }
248  
249          n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1);         /* word align rqst. */
# Line 381 | Line 384 | char   *p;
384          register M_HEAD *mp;
385          register int    bucket;
386  
387 <        if (p == NULL || p == DUMMYLOC)
387 >        if (p == NULL | p == DUMMYLOC)
388                  return(1);
389          mp = (M_HEAD *)p - 1;
390          if (mp->a.magic != MAGIC)               /* sanity check */
391                  return(0);
392          bucket = mp->a.bucket;
393 +        if (bucket < FIRSTBUCKET | bucket >= NBUCKETS)
394 +                return(0);
395          mp->next = free_list[bucket];
396          free_list[bucket] = mp;
397   #ifdef MSTATS
# Line 394 | Line 399 | char   *p;
399   #endif
400          return(1);
401   }
397
398
399 #ifndef NOVMEM
400 #ifndef BSD
401 #include <sys/var.h>
402 int
403 getpagesize()                   /* use SYSV var structure to get page size */
404 {
405        struct var  v;
406
407        uvar(&v);
408        return(1 << v.v_pageshift);
409 }
410 #endif
411 #endif
402  
403  
404   #ifdef MSTATS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines