aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2019-07-21 11:20:07 -0700
committerPaul Eggert2019-07-21 11:24:11 -0700
commit4a1507b88e813e3d54614f4cb59211234e05334a (patch)
treeb485378d180e4a23c4fbe42d022ed988f726f01c /src/alloc.c
parent51f5c1943121ffb8763fbb61e06630c2aa20e5c0 (diff)
downloademacs-4a1507b88e813e3d54614f4cb59211234e05334a.tar.gz
emacs-4a1507b88e813e3d54614f4cb59211234e05334a.zip
pure_alloc returns cleared memory
* src/alloc.c (pure_alloc): Clear any heap-allocated storage. This is simpler than auditing all the callers to make sure they don’t assume pure memory is cleared memory, and the performance implication is nonexistent except when Emacs is misconfigured. Also, add an assertion to catch caller misuse when pure space is exhausted.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 1718ce0fafc..b7ba886482e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5086,7 +5086,13 @@ valid_lisp_object_p (Lisp_Object obj)
5086/* Allocate room for SIZE bytes from pure Lisp storage and return a 5086/* Allocate room for SIZE bytes from pure Lisp storage and return a
5087 pointer to it. TYPE is the Lisp type for which the memory is 5087 pointer to it. TYPE is the Lisp type for which the memory is
5088 allocated. TYPE < 0 means it's not used for a Lisp object, 5088 allocated. TYPE < 0 means it's not used for a Lisp object,
5089 and that the result should have an alignment of -TYPE. */ 5089 and that the result should have an alignment of -TYPE.
5090
5091 The bytes are initially zero.
5092
5093 If pure space is exhausted, allocate space from the heap. This is
5094 merely an expedient to let Emacs warn that pure space was exhausted
5095 and that Emacs should be rebuilt with a larger pure space. */
5090 5096
5091static void * 5097static void *
5092pure_alloc (size_t size, int type) 5098pure_alloc (size_t size, int type)
@@ -5119,8 +5125,10 @@ pure_alloc (size_t size, int type)
5119 /* Don't allocate a large amount here, 5125 /* Don't allocate a large amount here,
5120 because it might get mmap'd and then its address 5126 because it might get mmap'd and then its address
5121 might not be usable. */ 5127 might not be usable. */
5122 purebeg = xmalloc (10000); 5128 int small_amount = 10000;
5123 pure_size = 10000; 5129 eassert (size <= small_amount - LISP_ALIGNMENT);
5130 purebeg = xzalloc (small_amount);
5131 pure_size = small_amount;
5124 pure_bytes_used_before_overflow += pure_bytes_used - size; 5132 pure_bytes_used_before_overflow += pure_bytes_used - size;
5125 pure_bytes_used = 0; 5133 pure_bytes_used = 0;
5126 pure_bytes_used_lisp = pure_bytes_used_non_lisp = 0; 5134 pure_bytes_used_lisp = pure_bytes_used_non_lisp = 0;