Mercurial > hg > xemacs-beta
comparison src/malloc.c @ 647:b39c14581166
[xemacs-hg @ 2001-08-13 04:45:47 by ben]
removal of unsigned, size_t, etc.
author | ben |
---|---|
date | Mon, 13 Aug 2001 04:46:48 +0000 |
parents | abe6d1db359e |
children | fdefd0186b75 |
comparison
equal
deleted
inserted
replaced
646:00c54252fe4f | 647:b39c14581166 |
---|---|
218 | 218 |
219 extern char etext; | 219 extern char etext; |
220 | 220 |
221 /* These two are for user programs to look at, when they are interested. */ | 221 /* These two are for user programs to look at, when they are interested. */ |
222 | 222 |
223 unsigned int malloc_sbrk_used; /* amount of data space used now */ | 223 Memory_Count malloc_sbrk_used; /* amount of data space used now */ |
224 unsigned int malloc_sbrk_unused; /* amount more we can have */ | 224 Memory_Count malloc_sbrk_unused; /* amount more we can have */ |
225 | 225 |
226 /* start of data space; can be changed by calling init_malloc */ | 226 /* start of data space; can be changed by calling init_malloc */ |
227 static char *data_space_start; | 227 static char *data_space_start; |
228 | 228 |
229 #ifdef MSTATS | 229 #ifdef MSTATS |
487 | 487 |
488 /* Figure out how many bytes are required, rounding up to the nearest | 488 /* Figure out how many bytes are required, rounding up to the nearest |
489 multiple of 8, then figure out which nestf[] area to use. | 489 multiple of 8, then figure out which nestf[] area to use. |
490 Both the beginning of the header and the beginning of the | 490 Both the beginning of the header and the beginning of the |
491 block should be on an eight byte boundary. */ | 491 block should be on an eight byte boundary. */ |
492 nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7; | 492 nbytes = (n + ((sizeof (*p) + 7) & ~7) + EXTRA + 7) & ~7; |
493 { | 493 { |
494 unsigned int shiftr = (nbytes - 1) >> 2; | 494 unsigned int shiftr = (nbytes - 1) >> 2; |
495 | 495 |
496 while (shiftr >>= 1) | 496 while (shiftr >>= 1) |
497 nunits++; | 497 nunits++; |
533 #ifdef rcheck | 533 #ifdef rcheck |
534 p -> mh_nbytes = n; | 534 p -> mh_nbytes = n; |
535 p -> mh_magic4 = MAGIC4; | 535 p -> mh_magic4 = MAGIC4; |
536 { | 536 { |
537 /* Get the location n after the beginning of the user's space. */ | 537 /* Get the location n after the beginning of the user's space. */ |
538 char *m = (char *) p + ((sizeof *p + 7) & ~7) + n; | 538 char *m = (char *) p + ((sizeof (*p) + 7) & ~7) + n; |
539 | 539 |
540 *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1; | 540 *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1; |
541 } | 541 } |
542 #else /* not rcheck */ | 542 #else /* not rcheck */ |
543 p -> mh_size = n; | 543 p -> mh_size = n; |
544 #endif /* not rcheck */ | 544 #endif /* not rcheck */ |
545 #ifdef MSTATS | 545 #ifdef MSTATS |
546 nmalloc[nunits]++; | 546 nmalloc[nunits]++; |
547 nmal++; | 547 nmal++; |
548 #endif /* MSTATS */ | 548 #endif /* MSTATS */ |
549 return (char *) p + ((sizeof *p + 7) & ~7); | 549 return (char *) p + ((sizeof (*p) + 7) & ~7); |
550 } | 550 } |
551 | 551 |
552 void | 552 void |
553 free (mem) | 553 free (mem) |
554 char *mem; | 554 char *mem; |
558 char *ap = mem; | 558 char *ap = mem; |
559 | 559 |
560 if (ap == 0) | 560 if (ap == 0) |
561 return; | 561 return; |
562 | 562 |
563 p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7)); | 563 p = (struct mhead *) (ap - ((sizeof (*p) + 7) & ~7)); |
564 if (p -> mh_alloc == ISMEMALIGN) | 564 if (p -> mh_alloc == ISMEMALIGN) |
565 { | 565 { |
566 ap -= p->mh_size; | 566 ap -= p->mh_size; |
567 p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7)); | 567 p = (struct mhead *) (ap - ((sizeof (*p) + 7) & ~7)); |
568 } | 568 } |
569 | 569 |
570 #ifndef rcheck | 570 #ifndef rcheck |
571 if (p -> mh_alloc != ISALLOC) | 571 if (p -> mh_alloc != ISALLOC) |
572 abort (); | 572 abort (); |
616 unsigned int nbytes; | 616 unsigned int nbytes; |
617 int nunits; | 617 int nunits; |
618 | 618 |
619 if (mem == 0) | 619 if (mem == 0) |
620 return malloc (n); | 620 return malloc (n); |
621 p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7)); | 621 p = (struct mhead *) (mem - ((sizeof (*p) + 7) & ~7)); |
622 nunits = p -> mh_index; | 622 nunits = p -> mh_index; |
623 ASSERT (p -> mh_alloc == ISALLOC); | 623 ASSERT (p -> mh_alloc == ISALLOC); |
624 #ifdef rcheck | 624 #ifdef rcheck |
625 ASSERT (p -> mh_magic4 == MAGIC4); | 625 ASSERT (p -> mh_magic4 == MAGIC4); |
626 { | 626 { |
628 ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1); | 628 ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1); |
629 ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1); | 629 ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1); |
630 } | 630 } |
631 #else /* not rcheck */ | 631 #else /* not rcheck */ |
632 if (p -> mh_index >= 13) | 632 if (p -> mh_index >= 13) |
633 tocopy = (1 << (p -> mh_index + 3)) - ((sizeof *p + 7) & ~7); | 633 tocopy = (1 << (p -> mh_index + 3)) - ((sizeof (*p) + 7) & ~7); |
634 else | 634 else |
635 tocopy = p -> mh_size; | 635 tocopy = p -> mh_size; |
636 #endif /* not rcheck */ | 636 #endif /* not rcheck */ |
637 | 637 |
638 /* See if desired size rounds to same power of 2 as actual size. */ | 638 /* See if desired size rounds to same power of 2 as actual size. */ |
639 nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7; | 639 nbytes = (n + ((sizeof (*p) + 7) & ~7) + EXTRA + 7) & ~7; |
640 | 640 |
641 /* If ok, use the same block, just marking its size as changed. */ | 641 /* If ok, use the same block, just marking its size as changed. */ |
642 if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) | 642 if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) |
643 { | 643 { |
644 #ifdef rcheck | 644 #ifdef rcheck |