From 83bd0157e1543b6bf6a22f008e58d3b420d4c77e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 12 Jan 2025 13:31:03 +0100 Subject: [PATCH] Remove inhibit_garbage_collection when HAVE_MPS This function call does nothing to stop GC with MPS. Remove it to save a few nanoseconds, and, more importantly, for documentation purposes. * src/alloc.c [HAVE_MPS] (allow_garbage_collection) (inhibit_garbage_collection): Remove function definitions. * src/lisp.h [HAVE_MPS] (inhibit_garbage_collection): Don't declare. * src/alloc.c [HAVE_MPS] (garbage_collect): * src/eval.c [HAVE_MPS] (probably_quit): * src/fns.c [HAVE_MPS] (hash_table_user_defined_call): * src/nsmenu.m [HAVE_MPS] (ns_menu_show): * src/term.c [HAVE_MPS] (tty_menu_show): * src/undo.c [HAVE_MPS] (truncate_undo_list): * src/xdisp.c [HAVE_MPS] (display_echo_area, decode_mode_spec): * src/xmenu.c [HAVE_MPS] (x_menu_show): Don't call inhibit_garbage_collection. Ref: https://lists.gnu.org/r/emacs-devel/2025-01/msg00362.html --- src/alloc.c | 6 ++++++ src/eval.c | 4 ++++ src/fns.c | 4 ++++ src/lisp.h | 2 ++ src/nsmenu.m | 2 ++ src/term.c | 7 +++++-- src/undo.c | 4 ++++ src/xdisp.c | 8 ++++++++ src/xmenu.c | 2 ++ 9 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index ffbde54b38e..d2c965ce7e7 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6385,6 +6385,7 @@ staticpro (Lisp_Object const *varaddress) Protection from GC ***********************************************************************/ +#ifndef HAVE_MPS /* Temporarily prevent garbage collection. Temporarily bump consing_until_gc to speed up maybe_gc when GC is inhibited. */ @@ -6404,6 +6405,7 @@ inhibit_garbage_collection (void) consing_until_gc = HI_THRESHOLD; return count; } +#endif /* Return the number of bytes in N objects each of size S, guarding against overflow if size_t is narrower than byte_ct. */ @@ -7030,7 +7032,11 @@ garbage_collect (void) if (!NILP (Vpost_gc_hook)) { +#ifdef HAVE_MPS + specpdl_ref gc_count = SPECPDL_INDEX (); +#else specpdl_ref gc_count = inhibit_garbage_collection (); +#endif safe_run_hooks (Qpost_gc_hook); unbind_to (gc_count, Qnil); } diff --git a/src/eval.c b/src/eval.c index b214870984c..45d9f8d2794 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1805,7 +1805,11 @@ process_quit_flag (void) void probably_quit (void) { +#ifdef HAVE_MPS + specpdl_ref gc_count = SPECPDL_INDEX (); +#else specpdl_ref gc_count = inhibit_garbage_collection (); +#endif if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) process_quit_flag (); else if (pending_signals) diff --git a/src/fns.c b/src/fns.c index f1106a73457..b91234f4bb9 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4734,7 +4734,11 @@ hash_table_user_defined_call (ptrdiff_t nargs, Lisp_Object *args, { if (!h->mutable) return Ffuncall (nargs, args); +#ifdef HAVE_MPS + specpdl_ref count = SPECPDL_INDEX (); +#else specpdl_ref count = inhibit_garbage_collection (); +#endif record_unwind_protect_ptr (restore_mutability, h); h->mutable = false; return unbind_to (count, Ffuncall (nargs, args)); diff --git a/src/lisp.h b/src/lisp.h index cb6d84cee71..9556b2c6774 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -5037,7 +5037,9 @@ #define ALLOCATE_ZEROED_PSEUDOVECTOR(type, field, tag) \ extern bool gc_in_progress; extern Lisp_Object make_float (double); extern void display_malloc_warning (void); +#ifndef HAVE_MPS extern specpdl_ref inhibit_garbage_collection (void); +#endif extern Lisp_Object build_symbol_with_pos (Lisp_Object, Lisp_Object); #ifndef HAVE_MPS extern void free_cons (struct Lisp_Cons *); diff --git a/src/nsmenu.m b/src/nsmenu.m index fa5a71084a9..eb16505e79a 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -915,8 +915,10 @@ - (NSRect)confinementRectForMenu:(NSMenu *)menu specpdl_count = SPECPDL_INDEX (); +#ifndef HAVE_MPS /* Don't GC due to a mysterious bug. */ inhibit_garbage_collection (); +#endif /* Loop over all panes and items, filling in the tree. */ i = 0; diff --git a/src/term.c b/src/term.c index e3cd121e7c3..231f9897c56 100644 --- a/src/term.c +++ b/src/term.c @@ -3694,7 +3694,6 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags, int dispwidth, dispheight; int i, j, lines, maxlines; int maxwidth; - specpdl_ref specpdl_count; eassert (FRAME_TERMCAP_P (f)); @@ -3711,9 +3710,13 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags, /* Make the menu on that window. */ menu = tty_menu_create (); +#ifdef HAVE_MPS + specpdl_ref specpdl_count = SPECPDL_INDEX (); +#else /* Don't GC while we prepare and show the menu, because we give the menu functions pointers to the contents of strings. */ - specpdl_count = inhibit_garbage_collection (); + specpdl_ref specpdl_count = inhibit_garbage_collection (); +#endif /* Avoid crashes if, e.g., another client will connect while we are in a menu. */ diff --git a/src/undo.c b/src/undo.c index 7a64abc20e7..42aca6b2d54 100644 --- a/src/undo.c +++ b/src/undo.c @@ -294,9 +294,13 @@ truncate_undo_list (struct buffer *b) Lisp_Object prev, next, last_boundary; intmax_t size_so_far = 0; +#ifdef HAVE_MPS + specpdl_ref count = SPECPDL_INDEX (); +#else /* Make sure that calling undo-outer-limit-function won't cause another GC. */ specpdl_ref count = inhibit_garbage_collection (); +#endif /* Make the buffer current to get its local values of variables such as undo_limit. Also so that Vundo_outer_limit_function can diff --git a/src/xdisp.c b/src/xdisp.c index 91f94356382..369055296e1 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -12930,12 +12930,16 @@ display_echo_area (struct window *w) { bool no_message_p, window_height_changed_p; +#ifdef HAVE_MPS + specpdl_ref count = SPECPDL_INDEX (); +#else /* Temporarily disable garbage collections while displaying the echo area. This is done because a GC can print a message itself. That message would modify the echo area buffer's contents while a redisplay of the buffer is going on, and seriously confuse redisplay. */ specpdl_ref count = inhibit_garbage_collection (); +#endif /* If there is no message, we must call display_echo_area_1 nevertheless because it resizes the window. But we will have to @@ -28995,7 +28999,11 @@ decode_mode_spec (struct window *w, register int c, int field_width, case '@': { +#ifdef HAVE_MPS + specpdl_ref count = SPECPDL_INDEX (); +#else specpdl_ref count = inhibit_garbage_collection (); +#endif Lisp_Object curdir = BVAR (current_buffer, directory); Lisp_Object val = Qnil; diff --git a/src/xmenu.c b/src/xmenu.c index ebcc23e2f20..13989f5a18c 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -2608,10 +2608,12 @@ x_menu_show (struct frame *f, int x, int y, int menuflags, goto return_entry; } +#ifndef HAVE_MPS /* Don't GC while we prepare and show the menu, because we give the oldxmenu library pointers to the contents of strings. */ inhibit_garbage_collection (); +#endif #ifdef HAVE_X_WINDOWS x_translate_coordinates_to_root (f, x, y, &x, &y); -- 2.47.1