[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 5018b66 4/6: Inhibit GC after inhibit_garbage_colle
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 5018b66 4/6: Inhibit GC after inhibit_garbage_collection |
Date: |
Sat, 20 Jul 2019 23:13:53 -0400 (EDT) |
branch: master
commit 5018b663c6c0d31f27fb44630a69d9e0bd73273d
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Inhibit GC after inhibit_garbage_collection
Without this patch, there are unlikely ways that garbage
collection could occur (sometimes causing undefined behavior)
even when inhibit_garbage_collection is in effect.
* src/alloc.c (garbage_collection_inhibited): New var.
(pure_alloc): Increment it if pure space is exhausted, so that
garbage_collect_1 no longer needs to inspect
pure_bytes_used_before_overflow.
(allow_garbage_collection): New function.
(inhibit_garbage_collection): Increment the new variable rather
than specbinding a user variable.
(garbage_collect_1): Do not garbage collect if the new variable
is set, rather than if pure_bytes_used_before_overflow is set.
---
src/alloc.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index 9d18fd9..09b3a4e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -292,6 +292,10 @@ static ptrdiff_t pure_bytes_used_lisp;
static ptrdiff_t pure_bytes_used_non_lisp;
+/* If positive, garbage collection is inhibited. Otherwise, zero. */
+
+static intptr_t garbage_collection_inhibited;
+
/* If nonzero, this is a warning delivered by malloc and not yet
displayed. */
@@ -5120,6 +5124,10 @@ pure_alloc (size_t size, int type)
pure_bytes_used_before_overflow += pure_bytes_used - size;
pure_bytes_used = 0;
pure_bytes_used_lisp = pure_bytes_used_non_lisp = 0;
+
+ /* Can't GC if pure storage overflowed because we can't determine
+ if something is a pure object or not. */
+ garbage_collection_inhibited++;
goto again;
}
@@ -5486,12 +5494,19 @@ staticpro (Lisp_Object const *varaddress)
/* Temporarily prevent garbage collection. */
+static void
+allow_garbage_collection (void)
+{
+ garbage_collection_inhibited--;
+}
+
ptrdiff_t
inhibit_garbage_collection (void)
{
ptrdiff_t count = SPECPDL_INDEX ();
- specbind (Qgc_cons_threshold, make_fixnum (MOST_POSITIVE_FIXNUM));
+ record_unwind_protect_void (allow_garbage_collection);
+ garbage_collection_inhibited++;
return count;
}
@@ -5779,9 +5794,7 @@ garbage_collect_1 (struct gcstat *gcst)
eassert (weak_hash_tables == NULL);
- /* Can't GC if pure storage overflowed because we can't determine
- if something is a pure object or not. */
- if (pure_bytes_used_before_overflow)
+ if (garbage_collection_inhibited)
return false;
/* Record this function, so it appears on the profiler's backtraces. */
- [Emacs-diffs] master updated (6490269 -> 515afc9), Paul Eggert, 2019/07/20
- [Emacs-diffs] master df5024d 2/6: Rename ‘pure’ to ‘purecopy’, Paul Eggert, 2019/07/20
- [Emacs-diffs] master 26de2d4 3/6: Simplify maybe_gc implementation, Paul Eggert, 2019/07/20
- [Emacs-diffs] master b0908a0 1/6: Fix hash table overallocation etc., Paul Eggert, 2019/07/20
- [Emacs-diffs] master 5018b66 4/6: Inhibit GC after inhibit_garbage_collection,
Paul Eggert <=
- [Emacs-diffs] master 515afc9 6/6: Fix crash if user test munges hash table, Paul Eggert, 2019/07/20
- [Emacs-diffs] master b6f194a 5/6: Simplify hashfn/cmpfn calling convention, Paul Eggert, 2019/07/20