comparison src/alloc.c @ 12529:c7d32f5da2b3

(Flist): Rewritten. (allocating_for_lisp): New variable. (init_intervals, make_interval, init_symbol, Fmake_symbol) (init_float, make_float, init_cons, Fcons) (allocate_vectorlike, init_marker, allocate_misc) (init_strings, make_uninit_string): Set allocate_misc temporarily.
author Karl Heuer <kwzh@gnu.org>
date Mon, 17 Jul 1995 22:10:25 +0000
parents 377cbbd8a2ad
children c5798bb57fdd
comparison
equal deleted inserted replaced
12528:ed5b91dd829a 12529:c7d32f5da2b3
99 #define SPARE_MEMORY (1 << 14) 99 #define SPARE_MEMORY (1 << 14)
100 100
101 /* Number of extra blocks malloc should get when it needs more core. */ 101 /* Number of extra blocks malloc should get when it needs more core. */
102 static int malloc_hysteresis; 102 static int malloc_hysteresis;
103 103
104 /* Nonzero when malloc is called for allocating Lisp object space. */
105 int allocating_for_lisp;
106
104 /* Non-nil means defun should do purecopy on the function definition */ 107 /* Non-nil means defun should do purecopy on the function definition */
105 Lisp_Object Vpurify_flag; 108 Lisp_Object Vpurify_flag;
106 109
107 #ifndef HAVE_SHM 110 #ifndef HAVE_SHM
108 EMACS_INT pure[PURESIZE / sizeof (EMACS_INT)] = {0,}; /* Force it into data space! */ 111 EMACS_INT pure[PURESIZE / sizeof (EMACS_INT)] = {0,}; /* Force it into data space! */
400 INTERVAL interval_free_list; 403 INTERVAL interval_free_list;
401 404
402 static void 405 static void
403 init_intervals () 406 init_intervals ()
404 { 407 {
408 allocating_for_lisp = 1;
405 interval_block 409 interval_block
406 = (struct interval_block *) malloc (sizeof (struct interval_block)); 410 = (struct interval_block *) malloc (sizeof (struct interval_block));
411 allocating_for_lisp = 0;
407 interval_block->next = 0; 412 interval_block->next = 0;
408 bzero (interval_block->intervals, sizeof interval_block->intervals); 413 bzero (interval_block->intervals, sizeof interval_block->intervals);
409 interval_block_index = 0; 414 interval_block_index = 0;
410 interval_free_list = 0; 415 interval_free_list = 0;
411 } 416 }
424 } 429 }
425 else 430 else
426 { 431 {
427 if (interval_block_index == INTERVAL_BLOCK_SIZE) 432 if (interval_block_index == INTERVAL_BLOCK_SIZE)
428 { 433 {
429 register struct interval_block *newi 434 register struct interval_block *newi;
430 = (struct interval_block *) xmalloc (sizeof (struct interval_block)); 435
431 436 allocating_for_lisp = 1;
437 newi = (struct interval_block *) xmalloc (sizeof (struct interval_block));
438
439 allocating_for_lisp = 0;
432 VALIDATE_LISP_STORAGE (newi, sizeof *newi); 440 VALIDATE_LISP_STORAGE (newi, sizeof *newi);
433 newi->next = interval_block; 441 newi->next = interval_block;
434 interval_block = newi; 442 interval_block = newi;
435 interval_block_index = 0; 443 interval_block_index = 0;
436 } 444 }
527 struct Lisp_Float *float_free_list; 535 struct Lisp_Float *float_free_list;
528 536
529 void 537 void
530 init_float () 538 init_float ()
531 { 539 {
540 allocating_for_lisp = 1;
532 float_block = (struct float_block *) malloc (sizeof (struct float_block)); 541 float_block = (struct float_block *) malloc (sizeof (struct float_block));
542 allocating_for_lisp = 0;
533 float_block->next = 0; 543 float_block->next = 0;
534 bzero (float_block->floats, sizeof float_block->floats); 544 bzero (float_block->floats, sizeof float_block->floats);
535 float_block_index = 0; 545 float_block_index = 0;
536 float_free_list = 0; 546 float_free_list = 0;
537 } 547 }
557 } 567 }
558 else 568 else
559 { 569 {
560 if (float_block_index == FLOAT_BLOCK_SIZE) 570 if (float_block_index == FLOAT_BLOCK_SIZE)
561 { 571 {
562 register struct float_block *new = (struct float_block *) xmalloc (sizeof (struct float_block)); 572 register struct float_block *new;
573
574 allocating_for_lisp = 1;
575 new = (struct float_block *) xmalloc (sizeof (struct float_block));
576 allocating_for_lisp = 0;
563 VALIDATE_LISP_STORAGE (new, sizeof *new); 577 VALIDATE_LISP_STORAGE (new, sizeof *new);
564 new->next = float_block; 578 new->next = float_block;
565 float_block = new; 579 float_block = new;
566 float_block_index = 0; 580 float_block_index = 0;
567 } 581 }
600 struct Lisp_Cons *cons_free_list; 614 struct Lisp_Cons *cons_free_list;
601 615
602 void 616 void
603 init_cons () 617 init_cons ()
604 { 618 {
619 allocating_for_lisp = 1;
605 cons_block = (struct cons_block *) malloc (sizeof (struct cons_block)); 620 cons_block = (struct cons_block *) malloc (sizeof (struct cons_block));
621 allocating_for_lisp = 0;
606 cons_block->next = 0; 622 cons_block->next = 0;
607 bzero (cons_block->conses, sizeof cons_block->conses); 623 bzero (cons_block->conses, sizeof cons_block->conses);
608 cons_block_index = 0; 624 cons_block_index = 0;
609 cons_free_list = 0; 625 cons_free_list = 0;
610 } 626 }
631 } 647 }
632 else 648 else
633 { 649 {
634 if (cons_block_index == CONS_BLOCK_SIZE) 650 if (cons_block_index == CONS_BLOCK_SIZE)
635 { 651 {
636 register struct cons_block *new = (struct cons_block *) xmalloc (sizeof (struct cons_block)); 652 register struct cons_block *new;
653 allocating_for_lisp = 1;
654 new = (struct cons_block *) xmalloc (sizeof (struct cons_block));
655 allocating_for_lisp = 0;
637 VALIDATE_LISP_STORAGE (new, sizeof *new); 656 VALIDATE_LISP_STORAGE (new, sizeof *new);
638 new->next = cons_block; 657 new->next = cons_block;
639 cons_block = new; 658 cons_block = new;
640 cons_block_index = 0; 659 cons_block_index = 0;
641 } 660 }
652 Any number of arguments, even zero arguments, are allowed.") 671 Any number of arguments, even zero arguments, are allowed.")
653 (nargs, args) 672 (nargs, args)
654 int nargs; 673 int nargs;
655 register Lisp_Object *args; 674 register Lisp_Object *args;
656 { 675 {
657 register Lisp_Object len, val, val_tail; 676 register Lisp_Object val = Qnil;
658 677
659 XSETFASTINT (len, nargs); 678 while (nargs--)
660 val = Fmake_list (len, Qnil); 679 val = Fcons (args[nargs], val);
661 val_tail = val;
662 while (!NILP (val_tail))
663 {
664 XCONS (val_tail)->car = *args++;
665 val_tail = XCONS (val_tail)->cdr;
666 }
667 return val; 680 return val;
668 } 681 }
669 682
670 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0, 683 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
671 "Return a newly created list of length LENGTH, with each element being INIT.") 684 "Return a newly created list of length LENGTH, with each element being INIT.")
692 allocate_vectorlike (len) 705 allocate_vectorlike (len)
693 EMACS_INT len; 706 EMACS_INT len;
694 { 707 {
695 struct Lisp_Vector *p; 708 struct Lisp_Vector *p;
696 709
710 allocating_for_lisp = 1;
697 p = (struct Lisp_Vector *)xmalloc (sizeof (struct Lisp_Vector) 711 p = (struct Lisp_Vector *)xmalloc (sizeof (struct Lisp_Vector)
698 + (len - 1) * sizeof (Lisp_Object)); 712 + (len - 1) * sizeof (Lisp_Object));
713 allocating_for_lisp = 0;
699 VALIDATE_LISP_STORAGE (p, 0); 714 VALIDATE_LISP_STORAGE (p, 0);
700 consing_since_gc += (sizeof (struct Lisp_Vector) 715 consing_since_gc += (sizeof (struct Lisp_Vector)
701 + (len - 1) * sizeof (Lisp_Object)); 716 + (len - 1) * sizeof (Lisp_Object));
702 717
703 p->next = all_vectors; 718 p->next = all_vectors;
799 struct Lisp_Symbol *symbol_free_list; 814 struct Lisp_Symbol *symbol_free_list;
800 815
801 void 816 void
802 init_symbol () 817 init_symbol ()
803 { 818 {
819 allocating_for_lisp = 1;
804 symbol_block = (struct symbol_block *) malloc (sizeof (struct symbol_block)); 820 symbol_block = (struct symbol_block *) malloc (sizeof (struct symbol_block));
821 allocating_for_lisp = 0;
805 symbol_block->next = 0; 822 symbol_block->next = 0;
806 bzero (symbol_block->symbols, sizeof symbol_block->symbols); 823 bzero (symbol_block->symbols, sizeof symbol_block->symbols);
807 symbol_block_index = 0; 824 symbol_block_index = 0;
808 symbol_free_list = 0; 825 symbol_free_list = 0;
809 } 826 }
826 } 843 }
827 else 844 else
828 { 845 {
829 if (symbol_block_index == SYMBOL_BLOCK_SIZE) 846 if (symbol_block_index == SYMBOL_BLOCK_SIZE)
830 { 847 {
831 struct symbol_block *new = (struct symbol_block *) xmalloc (sizeof (struct symbol_block)); 848 struct symbol_block *new;
849 allocating_for_lisp = 1;
850 new = (struct symbol_block *) xmalloc (sizeof (struct symbol_block));
851 allocating_for_lisp = 0;
832 VALIDATE_LISP_STORAGE (new, sizeof *new); 852 VALIDATE_LISP_STORAGE (new, sizeof *new);
833 new->next = symbol_block; 853 new->next = symbol_block;
834 symbol_block = new; 854 symbol_block = new;
835 symbol_block_index = 0; 855 symbol_block_index = 0;
836 } 856 }
864 union Lisp_Misc *marker_free_list; 884 union Lisp_Misc *marker_free_list;
865 885
866 void 886 void
867 init_marker () 887 init_marker ()
868 { 888 {
889 allocating_for_lisp = 1;
869 marker_block = (struct marker_block *) malloc (sizeof (struct marker_block)); 890 marker_block = (struct marker_block *) malloc (sizeof (struct marker_block));
891 allocating_for_lisp = 0;
870 marker_block->next = 0; 892 marker_block->next = 0;
871 bzero (marker_block->markers, sizeof marker_block->markers); 893 bzero (marker_block->markers, sizeof marker_block->markers);
872 marker_block_index = 0; 894 marker_block_index = 0;
873 marker_free_list = 0; 895 marker_free_list = 0;
874 } 896 }
886 } 908 }
887 else 909 else
888 { 910 {
889 if (marker_block_index == MARKER_BLOCK_SIZE) 911 if (marker_block_index == MARKER_BLOCK_SIZE)
890 { 912 {
891 struct marker_block *new 913 struct marker_block *new;
892 = (struct marker_block *) xmalloc (sizeof (struct marker_block)); 914 allocating_for_lisp = 1;
915 new = (struct marker_block *) xmalloc (sizeof (struct marker_block));
916 allocating_for_lisp = 0;
893 VALIDATE_LISP_STORAGE (new, sizeof *new); 917 VALIDATE_LISP_STORAGE (new, sizeof *new);
894 new->next = marker_block; 918 new->next = marker_block;
895 marker_block = new; 919 marker_block = new;
896 marker_block_index = 0; 920 marker_block_index = 0;
897 } 921 }
979 #endif 1003 #endif
980 1004
981 void 1005 void
982 init_strings () 1006 init_strings ()
983 { 1007 {
1008 allocating_for_lisp = 1;
984 current_string_block = (struct string_block *) malloc (sizeof (struct string_block)); 1009 current_string_block = (struct string_block *) malloc (sizeof (struct string_block));
1010 allocating_for_lisp = 0;
985 first_string_block = current_string_block; 1011 first_string_block = current_string_block;
986 consing_since_gc += sizeof (struct string_block); 1012 consing_since_gc += sizeof (struct string_block);
987 current_string_block->next = 0; 1013 current_string_block->next = 0;
988 current_string_block->prev = 0; 1014 current_string_block->prev = 0;
989 current_string_block->pos = 0; 1015 current_string_block->pos = 0;
1047 current_string_block->pos += fullsize; 1073 current_string_block->pos += fullsize;
1048 } 1074 }
1049 else if (fullsize > STRING_BLOCK_OUTSIZE) 1075 else if (fullsize > STRING_BLOCK_OUTSIZE)
1050 /* This string gets its own string block */ 1076 /* This string gets its own string block */
1051 { 1077 {
1052 register struct string_block *new 1078 register struct string_block *new;
1053 = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize); 1079 allocating_for_lisp = 1;
1080 new = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize);
1081 allocating_for_lisp = 0;
1054 VALIDATE_LISP_STORAGE (new, 0); 1082 VALIDATE_LISP_STORAGE (new, 0);
1055 consing_since_gc += sizeof (struct string_block_head) + fullsize; 1083 consing_since_gc += sizeof (struct string_block_head) + fullsize;
1056 new->pos = fullsize; 1084 new->pos = fullsize;
1057 new->next = large_string_blocks; 1085 new->next = large_string_blocks;
1058 large_string_blocks = new; 1086 large_string_blocks = new;
1061 ((struct string_block_head *)new + 1))); 1089 ((struct string_block_head *)new + 1)));
1062 } 1090 }
1063 else 1091 else
1064 /* Make a new current string block and start it off with this string */ 1092 /* Make a new current string block and start it off with this string */
1065 { 1093 {
1066 register struct string_block *new 1094 register struct string_block *new;
1067 = (struct string_block *) xmalloc (sizeof (struct string_block)); 1095 allocating_for_lisp = 1;
1096 new = (struct string_block *) xmalloc (sizeof (struct string_block));
1097 allocating_for_lisp = 0;
1068 VALIDATE_LISP_STORAGE (new, sizeof *new); 1098 VALIDATE_LISP_STORAGE (new, sizeof *new);
1069 consing_since_gc += sizeof (struct string_block); 1099 consing_since_gc += sizeof (struct string_block);
1070 current_string_block->next = new; 1100 current_string_block->next = new;
1071 new->prev = current_string_block; 1101 new->prev = current_string_block;
1072 new->next = 0; 1102 new->next = 0;