aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-09-05 13:25:43 -0700
committerPaul Eggert2019-09-05 13:27:07 -0700
commit16ab25f136c4eef27743dfa50953692d115f162c (patch)
treed38ff1b08714acdad771bbd2e92777370e9db2e6
parentb9e37f551add188f82f2583d3eb13cb81e707387 (diff)
downloademacs-16ab25f136c4eef27743dfa50953692d115f162c.tar.gz
emacs-16ab25f136c4eef27743dfa50953692d115f162c.zip
Fix bugs when recalculating consing_until_gc
Problem reported by Joseph Mingrone (Bug#37006#72). * src/alloc.c (watch_gc_cons_threshold) (watch_gc_cons_percentage): Don’t try to store an intmax_t into an int. Redo to make the code clearer. (watch_gc_cons_percentage): Use gc_cons_threshold, not consing_until_gc.
-rw-r--r--src/alloc.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 089f61f8339..5fc515f33be 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5783,18 +5783,18 @@ mark_and_sweep_weak_table_contents (void)
5783 5783
5784/* Return the number of bytes to cons between GCs, assuming 5784/* Return the number of bytes to cons between GCs, assuming
5785 gc-cons-threshold is THRESHOLD and gc-cons-percentage is 5785 gc-cons-threshold is THRESHOLD and gc-cons-percentage is
5786 GC_CONS_PERCENTAGE. */ 5786 PERCENTAGE. */
5787static intmax_t 5787static intmax_t
5788consing_threshold (intmax_t threshold, Lisp_Object gc_cons_percentage) 5788consing_threshold (intmax_t threshold, Lisp_Object percentage)
5789{ 5789{
5790 if (!NILP (Vmemory_full)) 5790 if (!NILP (Vmemory_full))
5791 return memory_full_cons_threshold; 5791 return memory_full_cons_threshold;
5792 else 5792 else
5793 { 5793 {
5794 threshold = max (threshold, GC_DEFAULT_THRESHOLD / 10); 5794 threshold = max (threshold, GC_DEFAULT_THRESHOLD / 10);
5795 if (FLOATP (gc_cons_percentage)) 5795 if (FLOATP (percentage))
5796 { 5796 {
5797 double tot = (XFLOAT_DATA (gc_cons_percentage) 5797 double tot = (XFLOAT_DATA (percentage)
5798 * total_bytes_of_live_objects ()); 5798 * total_bytes_of_live_objects ());
5799 if (threshold < tot) 5799 if (threshold < tot)
5800 { 5800 {
@@ -5825,11 +5825,12 @@ static Lisp_Object
5825watch_gc_cons_threshold (Lisp_Object symbol, Lisp_Object newval, 5825watch_gc_cons_threshold (Lisp_Object symbol, Lisp_Object newval,
5826 Lisp_Object operation, Lisp_Object where) 5826 Lisp_Object operation, Lisp_Object where)
5827{ 5827{
5828 intmax_t new_threshold; 5828 Lisp_Object percentage = Vgc_cons_percentage;
5829 int diff = (INTEGERP (newval) && integer_to_intmax (newval, &new_threshold) 5829 intmax_t threshold;
5830 ? (consing_threshold (new_threshold, Vgc_cons_percentage) 5830 intmax_t diff = (INTEGERP (newval) && integer_to_intmax (newval, &threshold)
5831 - consing_threshold (gc_cons_threshold, Vgc_cons_percentage)) 5831 ? (consing_threshold (threshold, percentage)
5832 : 0); 5832 - consing_threshold (gc_cons_threshold, percentage))
5833 : 0);
5833 return bump_consing_until_gc (diff); 5834 return bump_consing_until_gc (diff);
5834} 5835}
5835 5836
@@ -5838,8 +5839,9 @@ static Lisp_Object
5838watch_gc_cons_percentage (Lisp_Object symbol, Lisp_Object newval, 5839watch_gc_cons_percentage (Lisp_Object symbol, Lisp_Object newval,
5839 Lisp_Object operation, Lisp_Object where) 5840 Lisp_Object operation, Lisp_Object where)
5840{ 5841{
5841 int diff = (consing_threshold (consing_until_gc, newval) 5842 intmax_t threshold = gc_cons_threshold;
5842 - consing_threshold (consing_until_gc, Vgc_cons_percentage)); 5843 intmax_t diff = (consing_threshold (threshold, newval)
5844 - consing_threshold (threshold, Vgc_cons_percentage));
5843 return bump_consing_until_gc (diff); 5845 return bump_consing_until_gc (diff);
5844} 5846}
5845 5847