comparison src/alloc.c @ 89518:c9f7a2f363ca

Sync with HEAD version.
author Dave Love <fx@gnu.org>
date Wed, 17 Sep 2003 19:16:27 +0000
parents 2f877ed80fa6
children 68c22ea6027c
comparison
equal deleted inserted replaced
89517:d5ec115216af 89518:c9f7a2f363ca
550 if (!val && size) memory_full (); 550 if (!val && size) memory_full ();
551 return val; 551 return val;
552 } 552 }
553 553
554 554
555 /* Like free but block interrupt input.. */ 555 /* Like free but block interrupt input. */
556 556
557 void 557 void
558 xfree (block) 558 xfree (block)
559 POINTER_TYPE *block; 559 POINTER_TYPE *block;
560 { 560 {
709 /* Pointer to the (not necessarily aligned) malloc block. */ 709 /* Pointer to the (not necessarily aligned) malloc block. */
710 #ifdef HAVE_POSIX_MEMALIGN 710 #ifdef HAVE_POSIX_MEMALIGN
711 #define ABLOCKS_BASE(abase) (abase) 711 #define ABLOCKS_BASE(abase) (abase)
712 #else 712 #else
713 #define ABLOCKS_BASE(abase) \ 713 #define ABLOCKS_BASE(abase) \
714 (1 & (int) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1]) 714 (1 & (long) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1])
715 #endif 715 #endif
716 716
717 /* The list of free ablock. */ 717 /* The list of free ablock. */
718 static struct ablock *free_ablock; 718 static struct ablock *free_ablock;
719 719
736 allocated_mem_type = type; 736 allocated_mem_type = type;
737 #endif 737 #endif
738 738
739 if (!free_ablock) 739 if (!free_ablock)
740 { 740 {
741 int i, aligned; 741 int i;
742 EMACS_INT aligned; /* int gets warning casting to 64-bit pointer. */
742 743
743 #ifdef DOUG_LEA_MALLOC 744 #ifdef DOUG_LEA_MALLOC
744 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed 745 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed
745 because mapped region contents are not preserved in 746 because mapped region contents are not preserved in
746 a dumped Emacs. */ 747 a dumped Emacs. */
789 { 790 {
790 abase->blocks[i].abase = abase; 791 abase->blocks[i].abase = abase;
791 abase->blocks[i].x.next_free = free_ablock; 792 abase->blocks[i].x.next_free = free_ablock;
792 free_ablock = &abase->blocks[i]; 793 free_ablock = &abase->blocks[i];
793 } 794 }
794 ABLOCKS_BUSY (abase) = (struct ablocks *) aligned; 795 ABLOCKS_BUSY (abase) = (struct ablocks *) (long) aligned;
795 796
796 eassert (0 == ((EMACS_UINT)abase) % BLOCK_ALIGN); 797 eassert (0 == ((EMACS_UINT)abase) % BLOCK_ALIGN);
797 eassert (ABLOCK_ABASE (&abase->blocks[3]) == abase); /* 3 is arbitrary */ 798 eassert (ABLOCK_ABASE (&abase->blocks[3]) == abase); /* 3 is arbitrary */
798 eassert (ABLOCK_ABASE (&abase->blocks[0]) == abase); 799 eassert (ABLOCK_ABASE (&abase->blocks[0]) == abase);
799 eassert (ABLOCKS_BASE (abase) == base); 800 eassert (ABLOCKS_BASE (abase) == base);
800 eassert (aligned == (int)ABLOCKS_BUSY (abase)); 801 eassert (aligned == (long) ABLOCKS_BUSY (abase));
801 } 802 }
802 803
803 abase = ABLOCK_ABASE (free_ablock); 804 abase = ABLOCK_ABASE (free_ablock);
804 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (int) ABLOCKS_BUSY (abase)); 805 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (long) ABLOCKS_BUSY (abase));
805 val = free_ablock; 806 val = free_ablock;
806 free_ablock = free_ablock->x.next_free; 807 free_ablock = free_ablock->x.next_free;
807 808
808 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK 809 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK
809 if (val && type != MEM_TYPE_NON_LISP) 810 if (val && type != MEM_TYPE_NON_LISP)
831 #endif 832 #endif
832 /* Put on free list. */ 833 /* Put on free list. */
833 ablock->x.next_free = free_ablock; 834 ablock->x.next_free = free_ablock;
834 free_ablock = ablock; 835 free_ablock = ablock;
835 /* Update busy count. */ 836 /* Update busy count. */
836 ABLOCKS_BUSY (abase) = (struct ablocks *) (-2 + (int) ABLOCKS_BUSY (abase)); 837 ABLOCKS_BUSY (abase) = (struct ablocks *) (-2 + (long) ABLOCKS_BUSY (abase));
837 838
838 if (2 > (int) ABLOCKS_BUSY (abase)) 839 if (2 > (long) ABLOCKS_BUSY (abase))
839 { /* All the blocks are free. */ 840 { /* All the blocks are free. */
840 int i = 0, aligned = (int) ABLOCKS_BUSY (abase); 841 int i = 0, aligned = (long) ABLOCKS_BUSY (abase);
841 struct ablock **tem = &free_ablock; 842 struct ablock **tem = &free_ablock;
842 struct ablock *atop = &abase->blocks[aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1]; 843 struct ablock *atop = &abase->blocks[aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1];
843 844
844 while (*tem) 845 while (*tem)
845 { 846 {
1128 /* Initialize interval allocation. */ 1129 /* Initialize interval allocation. */
1129 1130
1130 static void 1131 static void
1131 init_intervals () 1132 init_intervals ()
1132 { 1133 {
1133 interval_block 1134 interval_block = NULL;
1134 = (struct interval_block *) lisp_malloc (sizeof *interval_block, 1135 interval_block_index = INTERVAL_BLOCK_SIZE;
1135 MEM_TYPE_NON_LISP);
1136 interval_block->next = 0;
1137 bzero ((char *) interval_block->intervals, sizeof interval_block->intervals);
1138 interval_block_index = 0;
1139 interval_free_list = 0; 1136 interval_free_list = 0;
1140 n_interval_blocks = 1; 1137 n_interval_blocks = 0;
1141 } 1138 }
1142 1139
1143 1140
1144 /* Return a new interval. */ 1141 /* Return a new interval. */
1145 1142
2722 /* Initialize symbol allocation. */ 2719 /* Initialize symbol allocation. */
2723 2720
2724 void 2721 void
2725 init_symbol () 2722 init_symbol ()
2726 { 2723 {
2727 symbol_block = (struct symbol_block *) lisp_malloc (sizeof *symbol_block, 2724 symbol_block = NULL;
2728 MEM_TYPE_SYMBOL); 2725 symbol_block_index = SYMBOL_BLOCK_SIZE;
2729 symbol_block->next = 0;
2730 bzero ((char *) symbol_block->symbols, sizeof symbol_block->symbols);
2731 symbol_block_index = 0;
2732 symbol_free_list = 0; 2726 symbol_free_list = 0;
2733 n_symbol_blocks = 1; 2727 n_symbol_blocks = 0;
2734 } 2728 }
2735 2729
2736 2730
2737 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0, 2731 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0,
2738 doc: /* Return a newly allocated uninterned symbol whose name is NAME. 2732 doc: /* Return a newly allocated uninterned symbol whose name is NAME.
2808 int n_marker_blocks; 2802 int n_marker_blocks;
2809 2803
2810 void 2804 void
2811 init_marker () 2805 init_marker ()
2812 { 2806 {
2813 marker_block = (struct marker_block *) lisp_malloc (sizeof *marker_block, 2807 marker_block = NULL;
2814 MEM_TYPE_MISC); 2808 marker_block_index = MARKER_BLOCK_SIZE;
2815 marker_block->next = 0;
2816 bzero ((char *) marker_block->markers, sizeof marker_block->markers);
2817 marker_block_index = 0;
2818 marker_free_list = 0; 2809 marker_free_list = 0;
2819 n_marker_blocks = 1; 2810 n_marker_blocks = 0;
2820 } 2811 }
2821 2812
2822 /* Return a newly allocated Lisp_Misc object, with no substructure. */ 2813 /* Return a newly allocated Lisp_Misc object, with no substructure. */
2823 2814
2824 Lisp_Object 2815 Lisp_Object
4349 4340
4350 gc_in_progress = 1; 4341 gc_in_progress = 1;
4351 4342
4352 /* clear_marks (); */ 4343 /* clear_marks (); */
4353 4344
4354 /* Mark all the special slots that serve as the roots of accessibility. 4345 /* Mark all the special slots that serve as the roots of accessibility. */
4355
4356 Usually the special slots to mark are contained in particular structures.
4357 Then we know no slot is marked twice because the structures don't overlap.
4358 In some cases, the structures point to the slots to be marked.
4359 For these, we use MARKBIT to avoid double marking of the slot. */
4360 4346
4361 for (i = 0; i < staticidx; i++) 4347 for (i = 0; i < staticidx; i++)
4362 mark_object (*staticvec[i]); 4348 mark_object (*staticvec[i]);
4363 4349
4364 #if (GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \ 4350 #if (GC_MARK_STACK == GC_MAKE_GCPROS_NOOPS \
4367 #else 4353 #else
4368 { 4354 {
4369 register struct gcpro *tail; 4355 register struct gcpro *tail;
4370 for (tail = gcprolist; tail; tail = tail->next) 4356 for (tail = gcprolist; tail; tail = tail->next)
4371 for (i = 0; i < tail->nvars; i++) 4357 for (i = 0; i < tail->nvars; i++)
4372 if (!XMARKBIT (tail->var[i])) 4358 mark_object (tail->var[i]);
4373 {
4374 mark_object (tail->var[i]);
4375 XMARK (tail->var[i]);
4376 }
4377 } 4359 }
4378 #endif 4360 #endif
4379 4361
4380 mark_byte_stack (); 4362 mark_byte_stack ();
4381 for (bind = specpdl; bind != specpdl_ptr; bind++) 4363 for (bind = specpdl; bind != specpdl_ptr; bind++)
4393 mark_object (handler->handler); 4375 mark_object (handler->handler);
4394 mark_object (handler->var); 4376 mark_object (handler->var);
4395 } 4377 }
4396 for (backlist = backtrace_list; backlist; backlist = backlist->next) 4378 for (backlist = backtrace_list; backlist; backlist = backlist->next)
4397 { 4379 {
4398 if (!XMARKBIT (*backlist->function)) 4380 mark_object (*backlist->function);
4399 { 4381
4400 mark_object (*backlist->function);
4401 XMARK (*backlist->function);
4402 }
4403 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) 4382 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
4404 i = 0; 4383 i = 0;
4405 else 4384 else
4406 i = backlist->nargs - 1; 4385 i = backlist->nargs - 1;
4407 for (; i >= 0; i--) 4386 for (; i >= 0; i--)
4408 if (!XMARKBIT (backlist->args[i])) 4387 mark_object (backlist->args[i]);
4409 {
4410 mark_object (backlist->args[i]);
4411 XMARK (backlist->args[i]);
4412 }
4413 } 4388 }
4414 mark_kboards (); 4389 mark_kboards ();
4415 4390
4416 /* Look thru every buffer's undo list 4391 /* Look thru every buffer's undo list
4417 for elements that update markers that were not marked, 4392 for elements that update markers that were not marked,
4473 4448
4474 #if (GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE \ 4449 #if (GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE \
4475 || GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES) 4450 || GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES)
4476 { 4451 {
4477 register struct gcpro *tail; 4452 register struct gcpro *tail;
4478
4479 for (tail = gcprolist; tail; tail = tail->next)
4480 for (i = 0; i < tail->nvars; i++)
4481 XUNMARK (tail->var[i]);
4482 } 4453 }
4483 #endif 4454 #endif
4484 4455
4485 unmark_byte_stack (); 4456 unmark_byte_stack ();
4486 for (backlist = backtrace_list; backlist; backlist = backlist->next)
4487 {
4488 XUNMARK (*backlist->function);
4489 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
4490 i = 0;
4491 else
4492 i = backlist->nargs - 1;
4493 for (; i >= 0; i--)
4494 XUNMARK (backlist->args[i]);
4495 }
4496 VECTOR_UNMARK (&buffer_defaults); 4457 VECTOR_UNMARK (&buffer_defaults);
4497 VECTOR_UNMARK (&buffer_local_symbols); 4458 VECTOR_UNMARK (&buffer_local_symbols);
4498 4459
4499 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0 4460 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES && 0
4500 dump_zombies (); 4461 dump_zombies ();
4675 struct mem_node *m; 4636 struct mem_node *m;
4676 #endif 4637 #endif
4677 int cdr_count = 0; 4638 int cdr_count = 0;
4678 4639
4679 loop: 4640 loop:
4680 XUNMARK (obj);
4681 4641
4682 if (PURE_POINTER_P (XPNTR (obj))) 4642 if (PURE_POINTER_P (XPNTR (obj)))
4683 return; 4643 return;
4684 4644
4685 last_marked[last_marked_index++] = obj; 4645 last_marked[last_marked_index++] = obj;
5742 5702
5743 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 5703 #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
5744 defsubr (&Sgc_status); 5704 defsubr (&Sgc_status);
5745 #endif 5705 #endif
5746 } 5706 }
5707
5708 /* arch-tag: 6695ca10-e3c5-4c2c-8bc3-ed26a7dda857
5709 (do not change this comment) */