aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/alloc.c b/src/alloc.c
index fe55cde49c9..03dacc77c6e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,6 +1,6 @@
1/* Storage allocation and gc for GNU Emacs Lisp interpreter. 1/* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 2
3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2015 Free Software 3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2016 Free Software
4Foundation, Inc. 4Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -2119,8 +2119,11 @@ INIT must be an integer that represents a character. */)
2119 { 2119 {
2120 nbytes = XINT (length); 2120 nbytes = XINT (length);
2121 val = make_uninit_string (nbytes); 2121 val = make_uninit_string (nbytes);
2122 memset (SDATA (val), c, nbytes); 2122 if (nbytes)
2123 SDATA (val)[nbytes] = 0; 2123 {
2124 memset (SDATA (val), c, nbytes);
2125 SDATA (val)[nbytes] = 0;
2126 }
2124 } 2127 }
2125 else 2128 else
2126 { 2129 {
@@ -2145,7 +2148,8 @@ INIT must be an integer that represents a character. */)
2145 memcpy (p, beg, len); 2148 memcpy (p, beg, len);
2146 } 2149 }
2147 } 2150 }
2148 *p = 0; 2151 if (nbytes)
2152 *p = 0;
2149 } 2153 }
2150 2154
2151 return val; 2155 return val;
@@ -3188,7 +3192,8 @@ allocate_vector (EMACS_INT len)
3188 if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len) 3192 if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len)
3189 memory_full (SIZE_MAX); 3193 memory_full (SIZE_MAX);
3190 v = allocate_vectorlike (len); 3194 v = allocate_vectorlike (len);
3191 v->header.size = len; 3195 if (len)
3196 v->header.size = len;
3192 return v; 3197 return v;
3193} 3198}
3194 3199
@@ -3727,7 +3732,7 @@ make_event_array (ptrdiff_t nargs, Lisp_Object *args)
3727#ifdef HAVE_MODULES 3732#ifdef HAVE_MODULES
3728/* Create a new module user ptr object. */ 3733/* Create a new module user ptr object. */
3729Lisp_Object 3734Lisp_Object
3730make_user_ptr (void (*finalizer) (void*), void *p) 3735make_user_ptr (void (*finalizer) (void *), void *p)
3731{ 3736{
3732 Lisp_Object obj; 3737 Lisp_Object obj;
3733 struct Lisp_User_Ptr *uptr; 3738 struct Lisp_User_Ptr *uptr;
@@ -4589,6 +4594,10 @@ maybe_lisp_pointer (void *p)
4589 return (uintptr_t) p % GCALIGNMENT == 0; 4594 return (uintptr_t) p % GCALIGNMENT == 0;
4590} 4595}
4591 4596
4597#ifndef HAVE_MODULES
4598enum { HAVE_MODULES = false };
4599#endif
4600
4592/* If P points to Lisp data, mark that as live if it isn't already 4601/* If P points to Lisp data, mark that as live if it isn't already
4593 marked. */ 4602 marked. */
4594 4603
@@ -4602,8 +4611,17 @@ mark_maybe_pointer (void *p)
4602 VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p)); 4611 VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p));
4603#endif 4612#endif
4604 4613
4605 if (!maybe_lisp_pointer (p)) 4614 if (sizeof (Lisp_Object) == sizeof (void *) || !HAVE_MODULES)
4606 return; 4615 {
4616 if (!maybe_lisp_pointer (p))
4617 return;
4618 }
4619 else
4620 {
4621 /* For the wide-int case, also mark emacs_value tagged pointers,
4622 which can be generated by emacs-module.c's value_to_lisp. */
4623 p = (void *) ((uintptr_t) p & ~(GCALIGNMENT - 1));
4624 }
4607 4625
4608 m = mem_find (p); 4626 m = mem_find (p);
4609 if (m != MEM_NIL) 4627 if (m != MEM_NIL)
@@ -4680,8 +4698,7 @@ mark_maybe_pointer (void *p)
4680static void ATTRIBUTE_NO_SANITIZE_ADDRESS 4698static void ATTRIBUTE_NO_SANITIZE_ADDRESS
4681mark_memory (void *start, void *end) 4699mark_memory (void *start, void *end)
4682{ 4700{
4683 void **pp; 4701 char *pp;
4684 int i;
4685 4702
4686 /* Make START the pointer to the start of the memory region, 4703 /* Make START the pointer to the start of the memory region,
4687 if it isn't already. */ 4704 if it isn't already. */
@@ -4692,6 +4709,8 @@ mark_memory (void *start, void *end)
4692 end = tem; 4709 end = tem;
4693 } 4710 }
4694 4711
4712 eassert (((uintptr_t) start) % GC_POINTER_ALIGNMENT == 0);
4713
4695 /* Mark Lisp data pointed to. This is necessary because, in some 4714 /* Mark Lisp data pointed to. This is necessary because, in some
4696 situations, the C compiler optimizes Lisp objects away, so that 4715 situations, the C compiler optimizes Lisp objects away, so that
4697 only a pointer to them remains. Example: 4716 only a pointer to them remains. Example:
@@ -4710,13 +4729,11 @@ mark_memory (void *start, void *end)
4710 away. The only reference to the life string is through the 4729 away. The only reference to the life string is through the
4711 pointer `s'. */ 4730 pointer `s'. */
4712 4731
4713 for (pp = start; (void *) pp < end; pp++) 4732 for (pp = start; (void *) pp < end; pp += GC_POINTER_ALIGNMENT)
4714 for (i = 0; i < sizeof *pp; i += GC_POINTER_ALIGNMENT) 4733 {
4715 { 4734 mark_maybe_pointer (*(void **) pp);
4716 void *p = *(void **) ((char *) pp + i); 4735 mark_maybe_object (*(Lisp_Object *) pp);
4717 mark_maybe_pointer (p); 4736 }
4718 mark_maybe_object (XIL ((intptr_t) p));
4719 }
4720} 4737}
4721 4738
4722#if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS 4739#if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS
@@ -5508,9 +5525,16 @@ garbage_collect_1 (void *end)
5508 don't let that cause a recursive GC. */ 5525 don't let that cause a recursive GC. */
5509 consing_since_gc = 0; 5526 consing_since_gc = 0;
5510 5527
5511 /* Save what's currently displayed in the echo area. */ 5528 /* Save what's currently displayed in the echo area. Don't do that
5512 message_p = push_message (); 5529 if we are GC'ing because we've run out of memory, since
5513 record_unwind_protect_void (pop_message_unwind); 5530 push_message will cons, and we might have no memory for that. */
5531 if (NILP (Vmemory_full))
5532 {
5533 message_p = push_message ();
5534 record_unwind_protect_void (pop_message_unwind);
5535 }
5536 else
5537 message_p = false;
5514 5538
5515 /* Save a copy of the contents of the stack, for debugging. */ 5539 /* Save a copy of the contents of the stack, for debugging. */
5516#if MAX_SAVE_STACK > 0 5540#if MAX_SAVE_STACK > 0
@@ -5641,7 +5665,7 @@ garbage_collect_1 (void *end)
5641 } 5665 }
5642 } 5666 }
5643 5667
5644 if (garbage_collection_messages) 5668 if (garbage_collection_messages && NILP (Vmemory_full))
5645 { 5669 {
5646 if (message_p || minibuf_level > 0) 5670 if (message_p || minibuf_level > 0)
5647 restore_message (); 5671 restore_message ();