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.11 by greg, Tue Dec 4 20:46:46 1990 UTC vs.
Revision 1.12 by greg, Tue Apr 2 09:36:21 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 46 | Line 46 | static unsigned        m_nwasted = 0;
46                                          /* malloc free lists */
47   typedef union m_head {
48          union m_head    *next;
49 <        int             bucket;
49 >        struct {
50 >                short           magic;
51 >                short           bucket;
52 >        }       a;
53          ALIGN           dummy;
54   } M_HEAD;
55  
56 + #define MAGIC           0x1a2           /* magic number for allocated memory */
57 +
58   #define FIRSTBUCKET     3
59   #define NBUCKETS        30
60  
61   static M_HEAD   *free_list[NBUCKETS];
62  
63 < static char     DUMMYLOC[BYTES_WORD];
63 > static ALIGN    dummy_mem;
64  
65 + #define DUMMYLOC        ((char *)&dummy_mem)
66  
67 +
68   char *
69   mscrounge(np)           /* search free lists to satisfy request */
70   register unsigned       *np;
# Line 196 | Line 203 | unsigned       n;
203                  mp = free_list[bucket];
204                  free_list[bucket] = mp->next;
205          }
206 <        mp->bucket = bucket;                    /* tag block */
206 >        mp->a.magic = MAGIC;                    /* tag block */
207 >        mp->a.bucket = bucket;
208          return((char *)(mp+1));
209   }
210  
# Line 209 | Line 217 | unsigned       n;
217          char    *p;
218          register unsigned       on;
219                                          /* get old size */
220 <        if (op != NULL && op != DUMMYLOC)
221 <                on = 1 << ((M_HEAD *)op-1)->bucket;
220 >        if (op != NULL && op != DUMMYLOC && ((M_HEAD *)op-1)->a.magic == MAGIC)
221 >                on = 1 << ((M_HEAD *)op-1)->a.bucket;
222          else
223                  on = 0;
224          if (n <= on && (n > on>>1 || on == 1<<FIRSTBUCKET))
# Line 236 | Line 244 | char   *p;
244          if (p == NULL || p == DUMMYLOC)
245                  return;
246          mp = (M_HEAD *)p - 1;
247 <        bucket = mp->bucket;
247 >        if (mp->a.magic != MAGIC)               /* sanity check */
248 >                return;
249 >        bucket = mp->a.bucket;
250          mp->next = free_list[bucket];
251          free_list[bucket] = mp;
252   #ifdef MSTATS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines