aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorEli Zaretskii2014-10-14 21:10:37 +0300
committerEli Zaretskii2014-10-14 21:10:37 +0300
commite3060a0c4d2f418ac786775109d71e5843ccf42e (patch)
tree347b37fc39d0db9cd23b3e9f79ee81b4bbc40f08 /src/alloc.c
parent1a3eca0656bdb764200e10a4f264138e94b1f3ce (diff)
parent980d78b3587560c13a46aef352ed8d5ed744acf6 (diff)
downloademacs-e3060a0c4d2f418ac786775109d71e5843ccf42e.tar.gz
emacs-e3060a0c4d2f418ac786775109d71e5843ccf42e.zip
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c107
1 files changed, 77 insertions, 30 deletions
diff --git a/src/alloc.c b/src/alloc.c
index ac154b587e6..faad0b59c87 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -80,7 +80,7 @@ static bool valgrind_p;
80 marked objects. */ 80 marked objects. */
81 81
82#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \ 82#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \
83 || defined GC_CHECK_MARKED_OBJECTS) 83 || defined HYBRID_MALLOC || defined GC_CHECK_MARKED_OBJECTS)
84#undef GC_MALLOC_CHECK 84#undef GC_MALLOC_CHECK
85#endif 85#endif
86 86
@@ -285,7 +285,7 @@ static void gc_sweep (void);
285static Lisp_Object make_pure_vector (ptrdiff_t); 285static Lisp_Object make_pure_vector (ptrdiff_t);
286static void mark_buffer (struct buffer *); 286static void mark_buffer (struct buffer *);
287 287
288#if !defined REL_ALLOC || defined SYSTEM_MALLOC 288#if !defined REL_ALLOC || defined SYSTEM_MALLOC || defined HYBRID_MALLOC
289static void refill_memory_reserve (void); 289static void refill_memory_reserve (void);
290#endif 290#endif
291static void compact_small_strings (void); 291static void compact_small_strings (void);
@@ -453,7 +453,7 @@ mmap_lisp_allowed_p (void)
453 /* If we can't store all memory addresses in our lisp objects, it's 453 /* If we can't store all memory addresses in our lisp objects, it's
454 risky to let the heap use mmap and give us addresses from all 454 risky to let the heap use mmap and give us addresses from all
455 over our address space. We also can't use mmap for lisp objects 455 over our address space. We also can't use mmap for lisp objects
456 if we might dump: unexec doesn't preserve the contents of mmaped 456 if we might dump: unexec doesn't preserve the contents of mmapped
457 regions. */ 457 regions. */
458 return pointers_fit_in_lispobj_p () && !might_dump; 458 return pointers_fit_in_lispobj_p () && !might_dump;
459} 459}
@@ -1014,10 +1014,17 @@ lisp_free (void *block)
1014 clang 3.3 anyway. */ 1014 clang 3.3 anyway. */
1015 1015
1016#if ! ADDRESS_SANITIZER 1016#if ! ADDRESS_SANITIZER
1017# if !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC 1017# if !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC
1018# define USE_ALIGNED_ALLOC 1 1018# define USE_ALIGNED_ALLOC 1
1019/* Defined in gmalloc.c. */ 1019/* Defined in gmalloc.c. */
1020void *aligned_alloc (size_t, size_t); 1020void *aligned_alloc (size_t, size_t);
1021# elif defined HYBRID_MALLOC
1022# if defined ALIGNED_ALLOC || defined HAVE_POSIX_MEMALIGN
1023# define USE_ALIGNED_ALLOC 1
1024# define aligned_alloc hybrid_aligned_alloc
1025/* Defined in gmalloc.c. */
1026void *aligned_alloc (size_t, size_t);
1027# endif
1021# elif defined HAVE_ALIGNED_ALLOC 1028# elif defined HAVE_ALIGNED_ALLOC
1022# define USE_ALIGNED_ALLOC 1 1029# define USE_ALIGNED_ALLOC 1
1023# elif defined HAVE_POSIX_MEMALIGN 1030# elif defined HAVE_POSIX_MEMALIGN
@@ -2219,7 +2226,6 @@ make_string (const char *contents, ptrdiff_t nbytes)
2219 return val; 2226 return val;
2220} 2227}
2221 2228
2222
2223/* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2229/* Make an unibyte string from LENGTH bytes at CONTENTS. */
2224 2230
2225Lisp_Object 2231Lisp_Object
@@ -2611,29 +2617,28 @@ list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4, L
2611Lisp_Object 2617Lisp_Object
2612listn (enum constype type, ptrdiff_t count, Lisp_Object arg, ...) 2618listn (enum constype type, ptrdiff_t count, Lisp_Object arg, ...)
2613{ 2619{
2614 va_list ap; 2620 Lisp_Object (*cons) (Lisp_Object, Lisp_Object);
2615 ptrdiff_t i; 2621 switch (type)
2616 Lisp_Object val, *objp; 2622 {
2623 case CONSTYPE_PURE: cons = pure_cons; break;
2624 case CONSTYPE_HEAP: cons = Fcons; break;
2625 default: emacs_abort ();
2626 }
2617 2627
2618 /* Change to SAFE_ALLOCA if you hit this eassert. */ 2628 eassume (0 < count);
2619 eassert (count <= MAX_ALLOCA / word_size); 2629 Lisp_Object val = cons (arg, Qnil);
2630 Lisp_Object tail = val;
2620 2631
2621 objp = alloca (count * word_size); 2632 va_list ap;
2622 objp[0] = arg;
2623 va_start (ap, arg); 2633 va_start (ap, arg);
2624 for (i = 1; i < count; i++) 2634 for (ptrdiff_t i = 1; i < count; i++)
2625 objp[i] = va_arg (ap, Lisp_Object);
2626 va_end (ap);
2627
2628 for (val = Qnil, i = count - 1; i >= 0; i--)
2629 { 2635 {
2630 if (type == CONSTYPE_PURE) 2636 Lisp_Object elem = cons (va_arg (ap, Lisp_Object), Qnil);
2631 val = pure_cons (objp[i], val); 2637 XSETCDR (tail, elem);
2632 else if (type == CONSTYPE_HEAP) 2638 tail = elem;
2633 val = Fcons (objp[i], val);
2634 else
2635 emacs_abort ();
2636 } 2639 }
2640 va_end (ap);
2641
2637 return val; 2642 return val;
2638} 2643}
2639 2644
@@ -3282,7 +3287,6 @@ See also the function `vector'. */)
3282 return vector; 3287 return vector;
3283} 3288}
3284 3289
3285
3286DEFUN ("vector", Fvector, Svector, 0, MANY, 0, 3290DEFUN ("vector", Fvector, Svector, 0, MANY, 0,
3287 doc: /* Return a newly created vector with specified arguments as elements. 3291 doc: /* Return a newly created vector with specified arguments as elements.
3288Any number of arguments, even zero arguments, are allowed. 3292Any number of arguments, even zero arguments, are allowed.
@@ -3829,7 +3833,7 @@ memory_full (size_t nbytes)
3829void 3833void
3830refill_memory_reserve (void) 3834refill_memory_reserve (void)
3831{ 3835{
3832#ifndef SYSTEM_MALLOC 3836#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
3833 if (spare_memory[0] == 0) 3837 if (spare_memory[0] == 0)
3834 spare_memory[0] = malloc (SPARE_MEMORY); 3838 spare_memory[0] = malloc (SPARE_MEMORY);
3835 if (spare_memory[1] == 0) 3839 if (spare_memory[1] == 0)
@@ -6011,8 +6015,9 @@ mark_overlay (struct Lisp_Overlay *ptr)
6011 for (; ptr && !ptr->gcmarkbit; ptr = ptr->next) 6015 for (; ptr && !ptr->gcmarkbit; ptr = ptr->next)
6012 { 6016 {
6013 ptr->gcmarkbit = 1; 6017 ptr->gcmarkbit = 1;
6014 mark_object (ptr->start); 6018 /* These two are always markers and can be marked fast. */
6015 mark_object (ptr->end); 6019 XMARKER (ptr->start)->gcmarkbit = 1;
6020 XMARKER (ptr->end)->gcmarkbit = 1;
6016 mark_object (ptr->plist); 6021 mark_object (ptr->plist);
6017 } 6022 }
6018} 6023}
@@ -7072,7 +7077,7 @@ detect_suspicious_free (void* ptr)
7072 7077
7073DEFUN ("suspicious-object", Fsuspicious_object, Ssuspicious_object, 1, 1, 0, 7078DEFUN ("suspicious-object", Fsuspicious_object, Ssuspicious_object, 1, 1, 0,
7074 doc: /* Return OBJ, maybe marking it for extra scrutiny. 7079 doc: /* Return OBJ, maybe marking it for extra scrutiny.
7075If Emacs is compiled with suspicous object checking, capture 7080If Emacs is compiled with suspicious object checking, capture
7076a stack trace when OBJ is freed in order to help track down 7081a stack trace when OBJ is freed in order to help track down
7077garbage collection bugs. Otherwise, do nothing and return OBJ. */) 7082garbage collection bugs. Otherwise, do nothing and return OBJ. */)
7078 (Lisp_Object obj) 7083 (Lisp_Object obj)
@@ -7100,8 +7105,48 @@ die (const char *msg, const char *file, int line)
7100 file, line, msg); 7105 file, line, msg);
7101 terminate_due_to_signal (SIGABRT, INT_MAX); 7106 terminate_due_to_signal (SIGABRT, INT_MAX);
7102} 7107}
7103#endif 7108
7104 7109#endif /* ENABLE_CHECKING */
7110
7111#if defined (ENABLE_CHECKING) && USE_STACK_LISP_OBJECTS
7112
7113/* Debugging check whether STR is ASCII-only. */
7114
7115const char *
7116verify_ascii (const char *str)
7117{
7118 const unsigned char *ptr = (unsigned char *) str, *end = ptr + strlen (str);
7119 while (ptr < end)
7120 {
7121 int c = STRING_CHAR_ADVANCE (ptr);
7122 if (!ASCII_CHAR_P (c))
7123 emacs_abort ();
7124 }
7125 return str;
7126}
7127
7128/* Stress alloca with inconveniently sized requests and check
7129 whether all allocated areas may be used for Lisp_Object. */
7130
7131NO_INLINE static void
7132verify_alloca (void)
7133{
7134 int i;
7135 enum { ALLOCA_CHECK_MAX = 256 };
7136 /* Start from size of the smallest Lisp object. */
7137 for (i = sizeof (struct Lisp_Cons); i <= ALLOCA_CHECK_MAX; i++)
7138 {
7139 void *ptr = alloca (i);
7140 make_lisp_ptr (ptr, Lisp_Cons);
7141 }
7142}
7143
7144#else /* not ENABLE_CHECKING && USE_STACK_LISP_OBJECTS */
7145
7146#define verify_alloca() ((void) 0)
7147
7148#endif /* ENABLE_CHECKING && USE_STACK_LISP_OBJECTS */
7149
7105/* Initialization. */ 7150/* Initialization. */
7106 7151
7107void 7152void
@@ -7111,6 +7156,8 @@ init_alloc_once (void)
7111 purebeg = PUREBEG; 7156 purebeg = PUREBEG;
7112 pure_size = PURESIZE; 7157 pure_size = PURESIZE;
7113 7158
7159 verify_alloca ();
7160
7114#if GC_MARK_STACK || defined GC_MALLOC_CHECK 7161#if GC_MARK_STACK || defined GC_MALLOC_CHECK
7115 mem_init (); 7162 mem_init ();
7116 Vdead = make_pure_string ("DEAD", 4, 4, 0); 7163 Vdead = make_pure_string ("DEAD", 4, 4, 0);