From 47580e0d72f53c2fff23cb8edf1487da76e87744 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Thu, 31 Dec 2015 10:59:40 +0900 Subject: Avoid writing to purespace * src/alloc.c (Fmake_string): Don't write to empty string contents. (allocate_vector): Don't write to empty vector size. * src/character.h (CHECK_CHARACTER_CAR, CHECK_CHARACTER_CDR): Don't call unnecessary XSETCAR or XSETCDR. * src/lisp.h (STRING_SET_UNIBYTE, STRING_SET_MULTIBYTE): Don't write to empty string size_byte. --- src/alloc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index fe55cde49c9..49f5b7f18bc 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2119,8 +2119,11 @@ INIT must be an integer that represents a character. */) { nbytes = XINT (length); val = make_uninit_string (nbytes); - memset (SDATA (val), c, nbytes); - SDATA (val)[nbytes] = 0; + if (nbytes) + { + memset (SDATA (val), c, nbytes); + SDATA (val)[nbytes] = 0; + } } else { @@ -2145,7 +2148,8 @@ INIT must be an integer that represents a character. */) memcpy (p, beg, len); } } - *p = 0; + if (nbytes) + *p = 0; } return val; @@ -3188,7 +3192,8 @@ allocate_vector (EMACS_INT len) if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len) memory_full (SIZE_MAX); v = allocate_vectorlike (len); - v->header.size = len; + if (len) + v->header.size = len; return v; } -- cgit v1.2.1 From 0e963201d03d9229bb8ac4323291d2b0119526ed Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 1 Jan 2016 01:16:19 -0800 Subject: Update copyright year to 2016 Run admin/update-copyright. --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 49f5b7f18bc..9ec44b8a2c3 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,6 +1,6 @@ /* Storage allocation and gc for GNU Emacs Lisp interpreter. -Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2015 Free Software +Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2016 Free Software Foundation, Inc. This file is part of GNU Emacs. -- cgit v1.2.1 From 09b2b8a5ce5b542856f93b645db51eb11cf9855a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 9 Jan 2016 21:15:12 -0500 Subject: * src/alloc.c (mark_maybe_pointer): Also check wide-int's emacs_value (mark_memory): Simplify loop. Don't assume a pointer-sized word can be cast to Lisp_Object. --- src/alloc.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 9ec44b8a2c3..e1b0d2e4a60 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4607,8 +4607,15 @@ mark_maybe_pointer (void *p) VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p)); #endif - if (!maybe_lisp_pointer (p)) - return; + if (sizeof (Lisp_Object) == sizeof (void *) || !HAVE_MODULES) + { + if (!maybe_lisp_pointer (p)) + return; + } + else + /* For the wide-int case, we also have to accept emacs_value "tagged + pointers", which can be generated by emacs-module.c's value_to_lisp. */ + p = (void*)((uintptr_t) p & ~(GCALIGNMENT - 1)); m = mem_find (p); if (m != MEM_NIL) @@ -4685,8 +4692,7 @@ mark_maybe_pointer (void *p) static void ATTRIBUTE_NO_SANITIZE_ADDRESS mark_memory (void *start, void *end) { - void **pp; - int i; + char *pp; /* Make START the pointer to the start of the memory region, if it isn't already. */ @@ -4697,6 +4703,8 @@ mark_memory (void *start, void *end) end = tem; } + eassert (((uintptr_t) start) % GC_POINTER_ALIGNMENT == 0); + /* Mark Lisp data pointed to. This is necessary because, in some situations, the C compiler optimizes Lisp objects away, so that only a pointer to them remains. Example: @@ -4715,13 +4723,11 @@ mark_memory (void *start, void *end) away. The only reference to the life string is through the pointer `s'. */ - for (pp = start; (void *) pp < end; pp++) - for (i = 0; i < sizeof *pp; i += GC_POINTER_ALIGNMENT) - { - void *p = *(void **) ((char *) pp + i); - mark_maybe_pointer (p); - mark_maybe_object (XIL ((intptr_t) p)); - } + for (pp = start; (void*)pp < end; pp = pp + GC_POINTER_ALIGNMENT) + { + mark_maybe_pointer (*(void **) pp); + mark_maybe_object (*(Lisp_Object *) pp); + } } #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS -- cgit v1.2.1 From d2c7fda9654a79423be8320bc2028263aefccced Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 10 Jan 2016 00:32:13 -0500 Subject: * src/alloc.c (mark_maybe_pointer): HAVE_MODULES may be undefined --- src/alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index e1b0d2e4a60..9d876a51469 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4607,7 +4607,13 @@ mark_maybe_pointer (void *p) VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p)); #endif - if (sizeof (Lisp_Object) == sizeof (void *) || !HAVE_MODULES) + if ( +#ifdef HAVE_MODULES + sizeof (Lisp_Object) == sizeof (void *) +#else + true +#endif + ) { if (!maybe_lisp_pointer (p)) return; -- cgit v1.2.1 From eef6784ea4932adbce24030b171df6c09bb4736a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Jan 2016 21:41:59 -0800 Subject: Simplify HAVE_MODULES use in mark_maybe_pointer * src/alloc.c (HAVE_MODULES): Now a constant 0 if not defined, so that later code can use 'if' rather than '#ifdef'. (mark_maybe_pointer): Simplify based on HAVE_MODULES now always working. --- src/alloc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 9d876a51469..8ceacfe8ead 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3732,7 +3732,7 @@ make_event_array (ptrdiff_t nargs, Lisp_Object *args) #ifdef HAVE_MODULES /* Create a new module user ptr object. */ Lisp_Object -make_user_ptr (void (*finalizer) (void*), void *p) +make_user_ptr (void (*finalizer) (void *), void *p) { Lisp_Object obj; struct Lisp_User_Ptr *uptr; @@ -4594,6 +4594,10 @@ maybe_lisp_pointer (void *p) return (uintptr_t) p % GCALIGNMENT == 0; } +#ifndef HAVE_MODULES +enum { HAVE_MODULES = false }; +#endif + /* If P points to Lisp data, mark that as live if it isn't already marked. */ @@ -4607,21 +4611,17 @@ mark_maybe_pointer (void *p) VALGRIND_MAKE_MEM_DEFINED (&p, sizeof (p)); #endif - if ( -#ifdef HAVE_MODULES - sizeof (Lisp_Object) == sizeof (void *) -#else - true -#endif - ) + if (sizeof (Lisp_Object) == sizeof (void *) || !HAVE_MODULES) { if (!maybe_lisp_pointer (p)) return; } else - /* For the wide-int case, we also have to accept emacs_value "tagged - pointers", which can be generated by emacs-module.c's value_to_lisp. */ - p = (void*)((uintptr_t) p & ~(GCALIGNMENT - 1)); + { + /* For the wide-int case, also mark emacs_value tagged pointers, + which can be generated by emacs-module.c's value_to_lisp. */ + p = (void *) ((uintptr_t) p & ~(GCALIGNMENT - 1)); + } m = mem_find (p); if (m != MEM_NIL) @@ -4729,7 +4729,7 @@ mark_memory (void *start, void *end) away. The only reference to the life string is through the pointer `s'. */ - for (pp = start; (void*)pp < end; pp = pp + GC_POINTER_ALIGNMENT) + for (pp = start; (void *) pp < end; pp += GC_POINTER_ALIGNMENT) { mark_maybe_pointer (*(void **) pp); mark_maybe_object (*(Lisp_Object *) pp); -- cgit v1.2.1 From 36b953947ee2ee0411139bd4ad7dcffdcc403036 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 11 Jan 2016 18:05:40 +0200 Subject: Avoid an infloop when we run out of memory * src/alloc.c (garbage_collect_1): Don't bother saving and restoring the echo-area message if we are GC'ing after running out of memory. This avoids an infloop due to repeated attempts to allocate memory for the cons cell needed to save the message, which signals the memory-full error, which attempts to save the echo-area message, which signals memory-full again, etc. --- src/alloc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 8ceacfe8ead..03dacc77c6e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5525,9 +5525,16 @@ garbage_collect_1 (void *end) don't let that cause a recursive GC. */ consing_since_gc = 0; - /* Save what's currently displayed in the echo area. */ - message_p = push_message (); - record_unwind_protect_void (pop_message_unwind); + /* Save what's currently displayed in the echo area. Don't do that + if we are GC'ing because we've run out of memory, since + push_message will cons, and we might have no memory for that. */ + if (NILP (Vmemory_full)) + { + message_p = push_message (); + record_unwind_protect_void (pop_message_unwind); + } + else + message_p = false; /* Save a copy of the contents of the stack, for debugging. */ #if MAX_SAVE_STACK > 0 @@ -5658,7 +5665,7 @@ garbage_collect_1 (void *end) } } - if (garbage_collection_messages) + if (garbage_collection_messages && NILP (Vmemory_full)) { if (message_p || minibuf_level > 0) restore_message (); -- cgit v1.2.1