[BACK]Return to malloc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / patch

Diff for /src/usr.bin/patch/Attic/malloc.c between version 1.2 and 1.3

version 1.2, 1996/06/10 11:21:29 version 1.3, 2001/11/19 19:02:15
Line 134 
Line 134 
   
 static  static
 morecore (nu)                   /* ask system for more memory */  morecore (nu)                   /* ask system for more memory */
     register int nu; {          /* size index to get more of  */      int nu; {           /* size index to get more of  */
         char   *sbrk ();          char   *sbrk ();
         register char  *cp;          char  *cp;
         register int    nblks;          int    nblks;
         register int    siz;          int    siz;
   
 #ifdef  M_WARN  #ifdef  M_WARN
 #ifndef BSD42  #ifndef BSD42
Line 214 
Line 214 
   
 static  static
 getpool () {  getpool () {
         register int nu;          int nu;
         register char *cp = sbrk (0);          char *cp = sbrk (0);
   
         if ((int) cp & 0x3ff)   /* land on 1K boundaries */          if ((int) cp & 0x3ff)   /* land on 1K boundaries */
             sbrk (1024 - ((int) cp & 0x3ff));              sbrk (1024 - ((int) cp & 0x3ff));
Line 245 
Line 245 
 char *  char *
 malloc (n)              /* get a block */  malloc (n)              /* get a block */
     unsigned n; {      unsigned n; {
         register struct  mhead *p;          struct  mhead *p;
         register unsigned int  nbytes;          unsigned int  nbytes;
         register int    nunits = 0;          int    nunits = 0;
   
         /* Figure out how many bytes are required, rounding up to the nearest          /* Figure out how many bytes are required, rounding up to the nearest
         multiple of 4, then figure out which nextf[] area to use */          multiple of 4, then figure out which nextf[] area to use */
         nbytes = (n + sizeof *p + EXTRA + 3) & ~3;          nbytes = (n + sizeof *p + EXTRA + 3) & ~3;
                 {                  {
                 register unsigned int   shiftr = (nbytes - 1) >> 2;                  unsigned int   shiftr = (nbytes - 1) >> 2;
   
                 while (shiftr >>= 1)                  while (shiftr >>= 1)
                     nunits++;                      nunits++;
Line 285 
Line 285 
         p -> mh_nbytes = n;          p -> mh_nbytes = n;
         p -> mh_magic4 = MAGIC4;          p -> mh_magic4 = MAGIC4;
                 {                  {
                 register char  *m = (char *) (p + 1) + n;                  char  *m = (char *) (p + 1) + n;
   
                 *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;                  *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
                 }                  }
Line 300 
Line 300 
   
 free (mem)  free (mem)
     char *mem; {      char *mem; {
         register struct mhead *p;          struct mhead *p;
                 {                  {
                 register char *ap = mem;                  char *ap = mem;
   
                 ASSERT (ap != 0);                  ASSERT (ap != 0);
                 p = (struct mhead *) ap - 1;                  p = (struct mhead *) ap - 1;
Line 315 
Line 315 
 #endif /* rcheck */  #endif /* rcheck */
                 }                  }
                 {                  {
                 register int nunits = p -> mh_index;                  int nunits = p -> mh_index;
   
                 ASSERT (nunits <= 29);                  ASSERT (nunits <= 29);
                 p -> mh_alloc = ISFREE;                  p -> mh_alloc = ISFREE;
Line 331 
Line 331 
 char *  char *
 realloc (mem, n)  realloc (mem, n)
     char *mem;      char *mem;
     register unsigned n; {      unsigned n; {
         register struct mhead *p;          struct mhead *p;
         register unsigned int tocopy;          unsigned int tocopy;
         register int nbytes;          int nbytes;
         register int nunits;          int nunits;
   
         if ((p = (struct mhead *) mem) == 0)          if ((p = (struct mhead *) mem) == 0)
             return malloc (n);              return malloc (n);
Line 345 
Line 345 
 #ifdef rcheck  #ifdef rcheck
         ASSERT (p -> mh_magic4 == MAGIC4);          ASSERT (p -> mh_magic4 == MAGIC4);
                 {                  {
                 register char *m = mem + (tocopy = p -> mh_nbytes);                  char *m = mem + (tocopy = p -> mh_nbytes);
                 ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);                  ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
                 ASSERT (*m++ == MAGIC1); ASSERT (*m   == MAGIC1);                  ASSERT (*m++ == MAGIC1); ASSERT (*m   == MAGIC1);
                 }                  }
Line 362 
Line 362 
         /* If ok, use the same block, just marking its size as changed.  */          /* If ok, use the same block, just marking its size as changed.  */
         if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) {          if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) {
 #ifdef rcheck  #ifdef rcheck
                 register char *m = mem + tocopy;                  char *m = mem + tocopy;
                 *m++ = 0;  *m++ = 0;  *m++ = 0;  *m++ = 0;                  *m++ = 0;  *m++ = 0;  *m++ = 0;  *m++ = 0;
                 p-> mh_nbytes = n;                  p-> mh_nbytes = n;
                 m = mem + n;                  m = mem + n;
Line 375 
Line 375 
         if (n < tocopy)          if (n < tocopy)
             tocopy = n;              tocopy = n;
                 {                  {
                 register char *new;                  char *new;
                 void bcopy();   /*HMS: here? */                  void bcopy();   /*HMS: here? */
   
                 if ((new = malloc (n)) == 0)                  if ((new = malloc (n)) == 0)
Line 399 
Line 399 
 malloc_stats (size)  malloc_stats (size)
     int size; {      int size; {
         struct mstats_value v;          struct mstats_value v;
         register int i;          int i;
         register struct mhead *p;          struct mhead *p;
   
         v.nfree = 0;          v.nfree = 0;
   
Line 421 
Line 421 
 /* how much space is available? */  /* how much space is available? */
   
 unsigned freespace() {  unsigned freespace() {
         register int i, j;          int i, j;
         register struct mhead *p;          struct mhead *p;
         register unsigned space = 0;          unsigned space = 0;
         int local;      /* address only is used */          int local;      /* address only is used */
   
         space = (char *)&local - sbrk(0);       /* stack space */          space = (char *)&local - sbrk(0);       /* stack space */
Line 438 
Line 438 
   
 unsigned mc_size(cp)  unsigned mc_size(cp)
     char *cp;{      char *cp;{
         register struct mhead *p;          struct mhead *p;
   
         if ((p = (struct mhead *) cp) == 0) {          if ((p = (struct mhead *) cp) == 0) {
                 /*HMS? */                  /*HMS? */
Line 460 
Line 460 
 /*HMS: Really should use memcpy, if available... */  /*HMS: Really should use memcpy, if available... */
   
 void bcopy(source, dest, len)  void bcopy(source, dest, len)
     register char *source, *dest;      char *source, *dest;
     register len; {      len; {
         register i;          i;
   
         for (i = 0; i < len; i++)          for (i = 0; i < len; i++)
             *dest++ = *source++;}              *dest++ = *source++;}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3