diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 100 |
1 files changed, 60 insertions, 40 deletions
diff --git a/src/alloc.c b/src/alloc.c index f44f22be1a7..5cb754d237b 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -4438,7 +4438,7 @@ mem_delete_fixup (struct mem_node *x) | |||
| 4438 | 4438 | ||
| 4439 | 4439 | ||
| 4440 | /* If P is a pointer into a live Lisp string object on the heap, | 4440 | /* If P is a pointer into a live Lisp string object on the heap, |
| 4441 | return the object. Otherwise, return nil. M is a pointer to the | 4441 | return the object's address. Otherwise, return NULL. M points to the |
| 4442 | mem_block for P. | 4442 | mem_block for P. |
| 4443 | 4443 | ||
| 4444 | This and other *_holding functions look for a pointer anywhere into | 4444 | This and other *_holding functions look for a pointer anywhere into |
| @@ -4446,7 +4446,7 @@ mem_delete_fixup (struct mem_node *x) | |||
| 4446 | because some compilers sometimes optimize away the latter. See | 4446 | because some compilers sometimes optimize away the latter. See |
| 4447 | Bug#28213. */ | 4447 | Bug#28213. */ |
| 4448 | 4448 | ||
| 4449 | static Lisp_Object | 4449 | static struct Lisp_String * |
| 4450 | live_string_holding (struct mem_node *m, void *p) | 4450 | live_string_holding (struct mem_node *m, void *p) |
| 4451 | { | 4451 | { |
| 4452 | if (m->type == MEM_TYPE_STRING) | 4452 | if (m->type == MEM_TYPE_STRING) |
| @@ -4462,23 +4462,23 @@ live_string_holding (struct mem_node *m, void *p) | |||
| 4462 | cp = ptr_bounds_copy (cp, b); | 4462 | cp = ptr_bounds_copy (cp, b); |
| 4463 | struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0]; | 4463 | struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0]; |
| 4464 | if (s->u.s.data) | 4464 | if (s->u.s.data) |
| 4465 | return make_lisp_ptr (s, Lisp_String); | 4465 | return s; |
| 4466 | } | 4466 | } |
| 4467 | } | 4467 | } |
| 4468 | return Qnil; | 4468 | return NULL; |
| 4469 | } | 4469 | } |
| 4470 | 4470 | ||
| 4471 | static bool | 4471 | static bool |
| 4472 | live_string_p (struct mem_node *m, void *p) | 4472 | live_string_p (struct mem_node *m, void *p) |
| 4473 | { | 4473 | { |
| 4474 | return !NILP (live_string_holding (m, p)); | 4474 | return live_string_holding (m, p) == p; |
| 4475 | } | 4475 | } |
| 4476 | 4476 | ||
| 4477 | /* If P is a pointer into a live Lisp cons object on the heap, return | 4477 | /* If P is a pointer into a live Lisp cons object on the heap, return |
| 4478 | the object. Otherwise, return nil. M is a pointer to the | 4478 | the object's address. Otherwise, return NULL. M points to the |
| 4479 | mem_block for P. */ | 4479 | mem_block for P. */ |
| 4480 | 4480 | ||
| 4481 | static Lisp_Object | 4481 | static struct Lisp_Cons * |
| 4482 | live_cons_holding (struct mem_node *m, void *p) | 4482 | live_cons_holding (struct mem_node *m, void *p) |
| 4483 | { | 4483 | { |
| 4484 | if (m->type == MEM_TYPE_CONS) | 4484 | if (m->type == MEM_TYPE_CONS) |
| @@ -4497,24 +4497,24 @@ live_cons_holding (struct mem_node *m, void *p) | |||
| 4497 | cp = ptr_bounds_copy (cp, b); | 4497 | cp = ptr_bounds_copy (cp, b); |
| 4498 | struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0]; | 4498 | struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0]; |
| 4499 | if (!deadp (s->u.s.car)) | 4499 | if (!deadp (s->u.s.car)) |
| 4500 | return make_lisp_ptr (s, Lisp_Cons); | 4500 | return s; |
| 4501 | } | 4501 | } |
| 4502 | } | 4502 | } |
| 4503 | return Qnil; | 4503 | return NULL; |
| 4504 | } | 4504 | } |
| 4505 | 4505 | ||
| 4506 | static bool | 4506 | static bool |
| 4507 | live_cons_p (struct mem_node *m, void *p) | 4507 | live_cons_p (struct mem_node *m, void *p) |
| 4508 | { | 4508 | { |
| 4509 | return !NILP (live_cons_holding (m, p)); | 4509 | return live_cons_holding (m, p) == p; |
| 4510 | } | 4510 | } |
| 4511 | 4511 | ||
| 4512 | 4512 | ||
| 4513 | /* If P is a pointer into a live Lisp symbol object on the heap, | 4513 | /* If P is a pointer into a live Lisp symbol object on the heap, |
| 4514 | return the object. Otherwise, return nil. M is a pointer to the | 4514 | return the object's address. Otherwise, return NULL. M points to the |
| 4515 | mem_block for P. */ | 4515 | mem_block for P. */ |
| 4516 | 4516 | ||
| 4517 | static Lisp_Object | 4517 | static struct Lisp_Symbol * |
| 4518 | live_symbol_holding (struct mem_node *m, void *p) | 4518 | live_symbol_holding (struct mem_node *m, void *p) |
| 4519 | { | 4519 | { |
| 4520 | if (m->type == MEM_TYPE_SYMBOL) | 4520 | if (m->type == MEM_TYPE_SYMBOL) |
| @@ -4533,16 +4533,16 @@ live_symbol_holding (struct mem_node *m, void *p) | |||
| 4533 | cp = ptr_bounds_copy (cp, b); | 4533 | cp = ptr_bounds_copy (cp, b); |
| 4534 | struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0]; | 4534 | struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0]; |
| 4535 | if (!deadp (s->u.s.function)) | 4535 | if (!deadp (s->u.s.function)) |
| 4536 | return make_lisp_symbol (s); | 4536 | return s; |
| 4537 | } | 4537 | } |
| 4538 | } | 4538 | } |
| 4539 | return Qnil; | 4539 | return NULL; |
| 4540 | } | 4540 | } |
| 4541 | 4541 | ||
| 4542 | static bool | 4542 | static bool |
| 4543 | live_symbol_p (struct mem_node *m, void *p) | 4543 | live_symbol_p (struct mem_node *m, void *p) |
| 4544 | { | 4544 | { |
| 4545 | return !NILP (live_symbol_holding (m, p)); | 4545 | return live_symbol_holding (m, p) == p; |
| 4546 | } | 4546 | } |
| 4547 | 4547 | ||
| 4548 | 4548 | ||
| @@ -4573,7 +4573,7 @@ live_float_p (struct mem_node *m, void *p) | |||
| 4573 | Otherwise, return nil. | 4573 | Otherwise, return nil. |
| 4574 | M is a pointer to the mem_block for P. */ | 4574 | M is a pointer to the mem_block for P. */ |
| 4575 | 4575 | ||
| 4576 | static Lisp_Object | 4576 | static struct Lisp_Vector * |
| 4577 | live_vector_holding (struct mem_node *m, void *p) | 4577 | live_vector_holding (struct mem_node *m, void *p) |
| 4578 | { | 4578 | { |
| 4579 | struct Lisp_Vector *vp = p; | 4579 | struct Lisp_Vector *vp = p; |
| @@ -4593,7 +4593,7 @@ live_vector_holding (struct mem_node *m, void *p) | |||
| 4593 | { | 4593 | { |
| 4594 | struct Lisp_Vector *next = ADVANCE (vector, vector_nbytes (vector)); | 4594 | struct Lisp_Vector *next = ADVANCE (vector, vector_nbytes (vector)); |
| 4595 | if (vp < next && !PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FREE)) | 4595 | if (vp < next && !PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FREE)) |
| 4596 | return make_lisp_ptr (vector, Lisp_Vectorlike); | 4596 | return vector; |
| 4597 | vector = next; | 4597 | vector = next; |
| 4598 | } | 4598 | } |
| 4599 | } | 4599 | } |
| @@ -4603,15 +4603,15 @@ live_vector_holding (struct mem_node *m, void *p) | |||
| 4603 | struct Lisp_Vector *vector = large_vector_vec (m->start); | 4603 | struct Lisp_Vector *vector = large_vector_vec (m->start); |
| 4604 | struct Lisp_Vector *next = ADVANCE (vector, vector_nbytes (vector)); | 4604 | struct Lisp_Vector *next = ADVANCE (vector, vector_nbytes (vector)); |
| 4605 | if (vector <= vp && vp < next) | 4605 | if (vector <= vp && vp < next) |
| 4606 | return make_lisp_ptr (vector, Lisp_Vectorlike); | 4606 | return vector; |
| 4607 | } | 4607 | } |
| 4608 | return Qnil; | 4608 | return NULL; |
| 4609 | } | 4609 | } |
| 4610 | 4610 | ||
| 4611 | static bool | 4611 | static bool |
| 4612 | live_vector_p (struct mem_node *m, void *p) | 4612 | live_vector_p (struct mem_node *m, void *p) |
| 4613 | { | 4613 | { |
| 4614 | return !NILP (live_vector_holding (m, p)); | 4614 | return live_vector_holding (m, p) == p; |
| 4615 | } | 4615 | } |
| 4616 | 4616 | ||
| 4617 | /* Mark OBJ if we can prove it's a Lisp_Object. */ | 4617 | /* Mark OBJ if we can prove it's a Lisp_Object. */ |
| @@ -4652,15 +4652,15 @@ mark_maybe_object (Lisp_Object obj) | |||
| 4652 | switch (XTYPE (obj)) | 4652 | switch (XTYPE (obj)) |
| 4653 | { | 4653 | { |
| 4654 | case Lisp_String: | 4654 | case Lisp_String: |
| 4655 | mark_p = EQ (obj, live_string_holding (m, po)); | 4655 | mark_p = live_string_p (m, po); |
| 4656 | break; | 4656 | break; |
| 4657 | 4657 | ||
| 4658 | case Lisp_Cons: | 4658 | case Lisp_Cons: |
| 4659 | mark_p = EQ (obj, live_cons_holding (m, po)); | 4659 | mark_p = live_cons_p (m, po); |
| 4660 | break; | 4660 | break; |
| 4661 | 4661 | ||
| 4662 | case Lisp_Symbol: | 4662 | case Lisp_Symbol: |
| 4663 | mark_p = EQ (obj, live_symbol_holding (m, po)); | 4663 | mark_p = live_symbol_p (m, po); |
| 4664 | break; | 4664 | break; |
| 4665 | 4665 | ||
| 4666 | case Lisp_Float: | 4666 | case Lisp_Float: |
| @@ -4668,7 +4668,7 @@ mark_maybe_object (Lisp_Object obj) | |||
| 4668 | break; | 4668 | break; |
| 4669 | 4669 | ||
| 4670 | case Lisp_Vectorlike: | 4670 | case Lisp_Vectorlike: |
| 4671 | mark_p = (EQ (obj, live_vector_holding (m, po))); | 4671 | mark_p = live_vector_p (m, po); |
| 4672 | break; | 4672 | break; |
| 4673 | 4673 | ||
| 4674 | default: | 4674 | default: |
| @@ -4713,43 +4713,63 @@ mark_maybe_pointer (void *p) | |||
| 4713 | m = mem_find (p); | 4713 | m = mem_find (p); |
| 4714 | if (m != MEM_NIL) | 4714 | if (m != MEM_NIL) |
| 4715 | { | 4715 | { |
| 4716 | Lisp_Object obj = Qnil; | 4716 | Lisp_Object obj; |
| 4717 | 4717 | ||
| 4718 | switch (m->type) | 4718 | switch (m->type) |
| 4719 | { | 4719 | { |
| 4720 | case MEM_TYPE_NON_LISP: | 4720 | case MEM_TYPE_NON_LISP: |
| 4721 | case MEM_TYPE_SPARE: | 4721 | case MEM_TYPE_SPARE: |
| 4722 | /* Nothing to do; not a pointer to Lisp memory. */ | 4722 | /* Nothing to do; not a pointer to Lisp memory. */ |
| 4723 | break; | 4723 | return; |
| 4724 | 4724 | ||
| 4725 | case MEM_TYPE_CONS: | 4725 | case MEM_TYPE_CONS: |
| 4726 | obj = live_cons_holding (m, p); | 4726 | { |
| 4727 | struct Lisp_Cons *h = live_cons_holding (m, p); | ||
| 4728 | if (!h) | ||
| 4729 | return; | ||
| 4730 | obj = make_lisp_ptr (h, Lisp_Cons); | ||
| 4731 | } | ||
| 4727 | break; | 4732 | break; |
| 4728 | 4733 | ||
| 4729 | case MEM_TYPE_STRING: | 4734 | case MEM_TYPE_STRING: |
| 4730 | obj = live_string_holding (m, p); | 4735 | { |
| 4736 | struct Lisp_String *h = live_string_holding (m, p); | ||
| 4737 | if (!h) | ||
| 4738 | return; | ||
| 4739 | obj = make_lisp_ptr (h, Lisp_String); | ||
| 4740 | } | ||
| 4731 | break; | 4741 | break; |
| 4732 | 4742 | ||
| 4733 | case MEM_TYPE_SYMBOL: | 4743 | case MEM_TYPE_SYMBOL: |
| 4734 | obj = live_symbol_holding (m, p); | 4744 | { |
| 4745 | struct Lisp_Symbol *h = live_symbol_holding (m, p); | ||
| 4746 | if (!h) | ||
| 4747 | return; | ||
| 4748 | obj = make_lisp_symbol (h); | ||
| 4749 | } | ||
| 4735 | break; | 4750 | break; |
| 4736 | 4751 | ||
| 4737 | case MEM_TYPE_FLOAT: | 4752 | case MEM_TYPE_FLOAT: |
| 4738 | if (live_float_p (m, p)) | 4753 | if (! live_float_p (m, p)) |
| 4739 | obj = make_lisp_ptr (p, Lisp_Float); | 4754 | return; |
| 4755 | obj = make_lisp_ptr (p, Lisp_Float); | ||
| 4740 | break; | 4756 | break; |
| 4741 | 4757 | ||
| 4742 | case MEM_TYPE_VECTORLIKE: | 4758 | case MEM_TYPE_VECTORLIKE: |
| 4743 | case MEM_TYPE_VECTOR_BLOCK: | 4759 | case MEM_TYPE_VECTOR_BLOCK: |
| 4744 | obj = live_vector_holding (m, p); | 4760 | { |
| 4761 | struct Lisp_Vector *h = live_vector_holding (m, p); | ||
| 4762 | if (!h) | ||
| 4763 | return; | ||
| 4764 | obj = make_lisp_ptr (h, Lisp_Vectorlike); | ||
| 4765 | } | ||
| 4745 | break; | 4766 | break; |
| 4746 | 4767 | ||
| 4747 | default: | 4768 | default: |
| 4748 | emacs_abort (); | 4769 | emacs_abort (); |
| 4749 | } | 4770 | } |
| 4750 | 4771 | ||
| 4751 | if (!NILP (obj)) | 4772 | mark_object (obj); |
| 4752 | mark_object (obj); | ||
| 4753 | } | 4773 | } |
| 4754 | } | 4774 | } |
| 4755 | 4775 | ||
| @@ -5679,7 +5699,7 @@ compact_font_cache_entry (Lisp_Object entry) | |||
| 5679 | struct font *font = GC_XFONT_OBJECT (val); | 5699 | struct font *font = GC_XFONT_OBJECT (val); |
| 5680 | 5700 | ||
| 5681 | if (!NILP (AREF (val, FONT_TYPE_INDEX)) | 5701 | if (!NILP (AREF (val, FONT_TYPE_INDEX)) |
| 5682 | && vectorlike_marked_p(&font->header)) | 5702 | && vectorlike_marked_p (&font->header)) |
| 5683 | break; | 5703 | break; |
| 5684 | } | 5704 | } |
| 5685 | if (CONSP (objlist)) | 5705 | if (CONSP (objlist)) |
| @@ -6518,7 +6538,7 @@ mark_object (Lisp_Object arg) | |||
| 6518 | structure allocated from the heap. */ | 6538 | structure allocated from the heap. */ |
| 6519 | #define CHECK_ALLOCATED() \ | 6539 | #define CHECK_ALLOCATED() \ |
| 6520 | do { \ | 6540 | do { \ |
| 6521 | if (pdumper_object_p(po)) \ | 6541 | if (pdumper_object_p (po)) \ |
| 6522 | { \ | 6542 | { \ |
| 6523 | if (!pdumper_object_p_precise (po)) \ | 6543 | if (!pdumper_object_p_precise (po)) \ |
| 6524 | emacs_abort (); \ | 6544 | emacs_abort (); \ |
| @@ -6533,7 +6553,7 @@ mark_object (Lisp_Object arg) | |||
| 6533 | function LIVEP. */ | 6553 | function LIVEP. */ |
| 6534 | #define CHECK_LIVE(LIVEP) \ | 6554 | #define CHECK_LIVE(LIVEP) \ |
| 6535 | do { \ | 6555 | do { \ |
| 6536 | if (pdumper_object_p(po)) \ | 6556 | if (pdumper_object_p (po)) \ |
| 6537 | break; \ | 6557 | break; \ |
| 6538 | if (!LIVEP (m, po)) \ | 6558 | if (!LIVEP (m, po)) \ |
| 6539 | emacs_abort (); \ | 6559 | emacs_abort (); \ |
| @@ -6590,7 +6610,7 @@ mark_object (Lisp_Object arg) | |||
| 6590 | break; | 6610 | break; |
| 6591 | 6611 | ||
| 6592 | #ifdef GC_CHECK_MARKED_OBJECTS | 6612 | #ifdef GC_CHECK_MARKED_OBJECTS |
| 6593 | if (!pdumper_object_p(po)) | 6613 | if (!pdumper_object_p (po)) |
| 6594 | { | 6614 | { |
| 6595 | m = mem_find (po); | 6615 | m = mem_find (po); |
| 6596 | if (m == MEM_NIL && !SUBRP (obj) && !main_thread_p (po)) | 6616 | if (m == MEM_NIL && !SUBRP (obj) && !main_thread_p (po)) |
| @@ -6642,7 +6662,7 @@ mark_object (Lisp_Object arg) | |||
| 6642 | /* bool vectors in a dump are permanently "marked", since | 6662 | /* bool vectors in a dump are permanently "marked", since |
| 6643 | they're in the old section and don't have mark bits. | 6663 | they're in the old section and don't have mark bits. |
| 6644 | If we're looking at a dumped bool vector, we should | 6664 | If we're looking at a dumped bool vector, we should |
| 6645 | have aborted above when we called vector_marked_p(), so | 6665 | have aborted above when we called vector_marked_p, so |
| 6646 | we should never get here. */ | 6666 | we should never get here. */ |
| 6647 | eassert (!pdumper_object_p (ptr)); | 6667 | eassert (!pdumper_object_p (ptr)); |
| 6648 | set_vector_marked (ptr); | 6668 | set_vector_marked (ptr); |
| @@ -6673,7 +6693,7 @@ mark_object (Lisp_Object arg) | |||
| 6673 | if (symbol_marked_p (ptr)) | 6693 | if (symbol_marked_p (ptr)) |
| 6674 | break; | 6694 | break; |
| 6675 | CHECK_ALLOCATED_AND_LIVE_SYMBOL (); | 6695 | CHECK_ALLOCATED_AND_LIVE_SYMBOL (); |
| 6676 | set_symbol_marked(ptr); | 6696 | set_symbol_marked (ptr); |
| 6677 | /* Attempt to catch bogus objects. */ | 6697 | /* Attempt to catch bogus objects. */ |
| 6678 | eassert (valid_lisp_object_p (ptr->u.s.function)); | 6698 | eassert (valid_lisp_object_p (ptr->u.s.function)); |
| 6679 | mark_object (ptr->u.s.function); | 6699 | mark_object (ptr->u.s.function); |